IntelliJ IDEA 2024.2 Help

Gradle dependencies

IntelliJ IDEA lets you add and manage dependencies in your Gradle project. You can add dependencies and view them in the diagram.

Generate Gradle dependencies

Any dependency added to the project is managed by Gradle. The best way to add or manage a dependency is in the build.gradle file. Dependencies that you set up manually inside IntelliJ IDEA module settings will be discarded on the next Gradle project reload.

Add a Gradle dependency

  1. Open the build.gradle file in the editor.

  2. Press Alt+Insert to open the Generate context menu.

  3. From the context menu, select Add Maven artifact dependency.

    Add dependency

    The Maven Artifact Search window opens.

  4. In the Maven Artifact Search window, in the search field, start typing the name of your dependency. In the list of results select the one you need and click Add.

    Search Artifact
  5. Reload your project.

    IntelliJ IDEA adds a dependency to the build.gradle file.

    Build script: added dependency

    IntelliJ IDEA also adds the dependency to the Dependencies node in the Gradle tool window and to the External Libraries in the Project tool window.

    Gradle tool window and Project tool window

    If the added dependency has its own transitive dependencies, IntelliJ IDEA displays them in both tool windows. Besides the transitive dependencies, IntelliJ IDEA also indicates cyclic dependencies in the Gradle tool window.

    Gradle tool window: cyclic dependencies

    If you add a dependency configuration of the source set, it will be displayed in the Gradle tool window as well.

    Source set dependency

View dependencies as a diagram

You can work with Gradle dependencies in the diagram format. It might be helpful when you have a large project and want to see the whole picture of how dependencies (including the transitive ones) are connected inside the project.

  1. In the Gradle tool window, select a project, on the toolbar, click the Show Dependencies icon or select the Show Dependencies option from the context menu.

    the Show Dependencies option

    You can select the Show Dependencies Popup (Ctrl+Alt+U) option to open the graph in a separate window. To close the popup, press Escape.

  2. In the diagram window, IntelliJ IDEA displays all project dependencies including the transitive ones.

    Gradle dependencies diagram

    When you navigate to a dependency in a graph, IntelliJ IDEA displays its version, group and artifact IDs.

    Show dependency information

Use the diagram window toolbar to manage the diagram. You can change the size of a diagram, export it to a file, see only a part of the diagram you are interested in, and so on.

Change the visibility level

You can change the visibility level and, for example, view dependencies that have a specific scope (compile, test, and so on).

  1. In the diagram window, select the project and click the Change Visibility Level icon.

  2. From the list, select the dependency scope you want to see. IntelliJ IDEA displays only the specified dependency scope.

    Changing visibility level

Show path from selection to root

You can select dependencies and see how they are connected to the root.

  1. In the diagram window, select a dependency for which you want to see the connection to a project. If you want to select several dependencies at once, hold down Shift and make the selection.

  2. On the toolbar, click the Show Path Root Selection icon.

Show Paths Root Selection

Show neighbors of the selected nodes

You can select dependencies and see what other dependencies are connected to the selected nodes. It might be helpful if you have a large diagram and want to focus on just a part of it.

  1. In the diagram window, select a dependency you need. If you want to select several dependencies at once, hold down Shift and make the selection.

  2. On the toolbar, click the Show Neighbors of Selected Nodes.

Show Neighbors of Selected Nodes

Search for a specific dependency in the graph

  1. In the diagram window, press Ctrl+F to open the Diagram Elements popup.

    Search for dependency
  2. Start typing a name of a dependency you want to find, select the one you need from the list of search results and press Enter. IntelliJ IDEA locates the needed dependency in the graph.

    Found dependency

View the diagram structure

  1. Generate a diagram.

  2. Click Structure in the left toolbar. IntelliJ IDEA opens the Structure tool window that displays a map of your diagram with a small preview of the selected block and its neighbors.

    the Structure view

    Use the context menu to zoom in and out, move canvas, change layout, and export part of the diagram into an image.

    the context menu

Dependency analyzer

Gradle dependency analyzer lets you quickly see and analyze resolved dependencies, the unresolved ones, dependencies with conflicts, and transitive dependencies in your project and subprojects.

Analyze dependencies

  1. On the toolbar in the Gradle tool window, click the Analyze Dependencies.

    Alternatively, in the Gradle tool window, right-click the needed dependency and select Analyze Dependencies from the context menu. You can also right-click a module in the Project view and use the same action.

    Resolved dependencies
  2. In the Dependency Analyzer window, you can narrow down your analysis scope, check only the conflicted dependencies, or check usages.

    If you want to see the needed dependency in the build.gradle file, right-click the dependency in the Usages part and select Go to Gradle Dependency. If you click Open Gradle Config on the project node, IntelliJ IDEA will open the build.gradle file.

    You can also click Go to Package Search to navigate to the dependency in question in the Work with the Dependencies tool window.

    If the duplicate dependency is found, it will be greyed out.

    For more information about available options and icons in the Dependency Analyzer window, refer to the reference section.

Dependency analyzer tool window reference

Item

Description

Scope

You can see scopes in which every dependency is used in the project. To narrow down the list of the dependencies based on their scope, select the appropriate option from the list of scopes.

Dependency analyzer: dependency scope

Show Conflicts Only

Click the Conflicts icon to see only unresolved or conflicted dependencies.

Dependencies with conflicts

Show GroupId

Click Show GroupId and select Show GroupId to display GroupId in the list of dependencies.

Show as Tree

Toggle Show as Tree to display the list of dependencies in a form of nodes or in the flat list.

The tree view will help you quickly check the transitive dependencies.

Expand / Collapse

Use the Expand All icon/the Collapse All icon expand or collapse the list of dependencies.

Last modified: 11 October 2024