# Dependencies analysis

If you have a large Java project with several modules that uses multiple libraries, any operation that requires an essential structural change can be difficult. For example, if you decide to remove one of the libraries, extract an API or a new module, or modularize your application by switching to [Java 9 Jigsaw](https://openjdk.java.net/projects/jigsaw/) modules, you need to analyze dependencies within your project in order to make sure that your change is not breaking anything.

IntelliJ IDEA has a tool that allows you to [analyze dependencies](#analyze-dependencies) between modules, packages, and classes in your application and prepare for structural changes — the dependency analyzer.

> **Tip:**
> In IntelliJ IDEA, you can visualize dependencies between the parts of a project (modules, classes, and so on) and highlight the information flow using the [Dependency Structure analysis](dsm-analysis.html).

## Analyze dependencies

Procedure:

1. In the main menu, go to `Code | Analyze Code | Dependencies`.

Alternatively, if you want to analyze a specific item, right-click it in the Project tool window and select `Analyze | Analyze Dependencies`.

2. In the dialog that opens, specify the scope of files that you want to analyze.

![Selecting the scope of the analysis](https://resources.jetbrains.com.cn/help/img/idea/2026.2/dependency-analysis-scope-dialog.png)

If the necessary scope is not created yet, click ![the Add scope (Insert) icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and [define a new scope](configuring-scopes-and-file-colors.html#creating-a-new-custom-scope) in the dialog that opens.

3. Select the Include test sources option if you want to analyze your test code together with the production code.

4. Select the Show transitive dependencies option if you want to analyze transitive dependencies and specify the necessary threshold.

For example, A depends on B, and B depends on C. By setting the threshold to 1, the IDE will display B and C dependencies for A. By setting the threshold to 0, only B dependencies will be displayed for A.

5. Click Analyze to run the analysis.

When the analysis is finished, the results are displayed in the Dependency Viewer tool window.

6. In the left pane of the tool window, select the node in which you want to search for dependencies.

7. In the right pane, select the node on which the selected node depends.

Search results are displayed in the lower pane of the tool window. Use the [options](#toolbar1) on the toolbar to manage your search results.

![Dependencies analysis results in the tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/analyze-dependencies-results.png)

## Analyze module dependencies

Module dependencies analysis shows all modules that exist in the specified scope, the relationships between these modules as they are specified in the [Dependencies](working-with-module-dependencies.html) tab of the Project Structure dialog, and the cyclic dependencies between the modules.

You can use this type of analysis to make sure that the dependencies you have previously defined still exist in your project.

Procedure:

1. In the main menu, go to `Code | Analyze Code | Module Dependencies`.

If there are no selected modules in the Project tool window, you will be prompted to specify the scope of analysis. You can inspect the whole project, the current module, or a module group.

Alternatively, right-click a module in the Project tool window and select `Analyze | Analyze Module Dependencies`.

2. The Module Dependencies tool window opens listing all modules withing the selected scope of files.

If any [cyclic dependencies](#cyclic) are found in the selected module, they are shown in the right part of the tool window.

![Module Dependencies tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/analyzeModuleDependencies.png)

3. Select a module in the tree view and click ![the Analyze Dependencies button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.ide.hectorOff.svg) on the toolbar of the Module Dependencies tool window to find the modules that depend on the selected one.

4. In the dialog that opens, specify the scope of files that you want to analyze.

5. Select the Include test sources option if you want to analyze your test code together with the production code.

6. Select the Show transitive dependencies option if you want to analyze transitive dependencies and specify the necessary threshold.

For example, A depends on B, and B depends on C. By setting the threshold to 1, the IDE will display B and C dependencies for A. By setting the threshold to 0, only B dependencies will be displayed for A.

7. Click Analyze to run the analysis.

When the analysis is finished, the results are displayed in the Dependency Viewer tool window.

8. In the left pane of the tool window, select the node in which you want to search for dependencies.

9. In the right pane, select the node on which the selected node depends.

Search results are displayed in the lower pane of the tool window. Use the [options](#toolbar1) on the toolbar to manage your search.

### Module Dependencies tool window

This tool window is available after you run the Analyze Module Dependencies option and displays module dependencies as they are defined in the module settings. In this tool window, you can change the direction of the dependencies and perform a more detailed analysis of the source code.

#### Toolbar buttons

| Item | Description |
| --- | --- |
|  ![Close](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.close.svg)  | Close the current tab. |
|  ![Analyze Dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.rerun.svg)  | Open the Specify Dependency Analysis Scope dialog and analyze dependencies.  |
|  ![Backward Dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.hierarchy.subtypes.svg)  | Change the direction of dependencies. |
|  ![Include Test Dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.nodes.testSourceFolder.png)  | Include test dependencies. |

#### Context menu options

| Item | Shortcut | Description |
| --- | --- | --- |
| Expand All / Collapse All |  `Ctrl+NumPad +` (Windows), `⌘ NumPad +` (macOS), `⌘ NumPad +` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad +` (macOS System Shortcuts), `Ctrl+NumPad +` (XWin), `Ctrl+NumPad +` (GNOME), `Ctrl+NumPad +` (KDE), `Ctrl+NumPad +` (Emacs), `Ctrl+NumPad +` (Sublime Text), `⌘ NumPad +` (Sublime Text (macOS)), `Ctrl+NumPad +` (NetBeans), `Ctrl+NumPad +` (Visual Studio), `⌘ NumPad +` (Visual Studio (macOS)), `Ctrl+Shift+NumPad *` (Eclipse), `⌘ ⇧ NumPad *` (Eclipse (macOS)) / `Ctrl+NumPad -` (Windows), `⌘ NumPad -` (macOS), `⌘ NumPad -` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad -` (macOS System Shortcuts), `Ctrl+NumPad -` (XWin), `Ctrl+NumPad -` (GNOME), `Ctrl+NumPad -` (KDE), `Ctrl+NumPad -` (Emacs), `Ctrl+NumPad -` (Sublime Text), `⌘ NumPad -` (Sublime Text (macOS)), `Ctrl+NumPad -` (NetBeans), `Ctrl+NumPad -` (Visual Studio), `⌘ NumPad -` (Visual Studio (macOS)), `Ctrl+Shift+NumPad /` (Eclipse), `⌘ ⇧ NumPad /` (Eclipse (macOS))  | Fold or unfold all nodes. |
| Open Module Settings |  `F4` (Windows), `⌘ ↓` (macOS), `F4` (IntelliJ IDEA Classic (macOS)), `F4` (macOS System Shortcuts), `F4` (XWin), `F4` (GNOME), `F4` (KDE), `F4` (Emacs), `F4` (Sublime Text), `F4` (Sublime Text (macOS)), `F4` (NetBeans), `F4` (Visual Studio), `⌘ ↓` (Visual Studio (macOS)), `F12` (Eclipse), `F3` (Eclipse (macOS)) `Ctrl+Enter` (Windows), `⌘ ⏎` (macOS), `⌘ ⏎` (IntelliJ IDEA Classic (macOS)), `⌘ ⏎` (macOS System Shortcuts), `Ctrl+Enter` (XWin), `Ctrl+Enter` (GNOME), `Ctrl+Enter` (KDE), `Ctrl+Enter` (Emacs), `Ctrl+Enter` (Sublime Text), `⌘ ⏎` (Sublime Text (macOS)), `Ctrl+Enter` (NetBeans), `Ctrl+Enter` (Visual Studio), `⌘ ⏎` (Visual Studio (macOS)), `Ctrl+Enter` (Eclipse), `⌘ ⏎` (Eclipse (macOS))  | Open settings of the selected module in the Modules page of the Project Structure dialog (`Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS))). |
|    Analyze Dependencies     Analyze Backward Dependencies     Analyze Cyclic Dependencies    |  | Select one of these options to analyze dependencies. |

> **Tip:**
> For a visual representation of module dependencies in your project, use [module dependency diagrams](project-module-dependencies-diagram.html).

## Analyze cyclic dependencies

By analyzing cyclic dependencies, you can detect circular relationships between packages in the specified scope.

For example, a cycle occurs when classes from package 1 reference classes from package 2, classes from package 2 reference classes from package 3, and classes from package 3 reference classes from package 1.

![Cyclic dependencies on a scheme](https://resources.jetbrains.com.cn/help/img/idea/2026.2/cycle-dependencies-scheme.png)

Procedure:

1. In the main menu, go to `Code | Analyze Code | Cyclic Dependencies`.

Alternatively, right-click an item in the Project tool window and select `Analyze | Analyze Cyclic Dependencies`.

2. In the Specify Cyclic Dependency Analysis Scope dialog, select the scope of files that you want to analyze.

3. Select the Include test sources option if you want to analyze your test code together with the production code.

![Selecting a scope for analyzing cyclic dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/cyclic-dependencies.png)

4. Click OK to run the analysis.

When the analysis is finished, the results are displayed in the Dependency Viewer tool window.

5. In the left pane of the tool window, select the node in which you want to search for cyclic dependencies.

6. Search results are displayed in the right pane. Use the [options](#toolbar1) on the toolbar to manage your search results.

![Results of cyclic dependencies analysis shown in the tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/cyclic-dependencies-results.png)

## Analyze backward dependencies

With this type of analysis, you can find other classes or modules in a certain range of files that depend on the specified scope of analysis (the whole project, a module, a file, unversioned files, and so on).

Analyzing backward dependencies might be time-consuming, especially in large projects.

Procedure:

1. In the main menu, go to `Code | Analyze Code | Backward Dependencies`.

Alternatively, if you want to analyze a specific item, right-click it in the Project tool window and select `Analyze | Analyze Backward Dependencies`.

2. In the Analysis Scope section of the dialog, specify the part of your project for which you want to find the dependencies.

3. Select the Include test sources checkbox to analyze the test sources.

4. In the Analyze usages in: section, specify the scope in which you want to search for dependencies.

![Running the backward dependencies analysis](https://resources.jetbrains.com.cn/help/img/idea/2026.2/backward-dependencies.png)

5. When the analysis is finished, the results are displayed in the Dependency Viewer tool window.

6. In the left pane of the tool window, select the file or the scope of files that you want to search for.

7. In the right pane, select the scope in which you want to search the selected dependencies.

Search results are displayed in the lower pane of the tool window. Use the [options](#toolbar1) on the toolbar to manage your search.

## Dependency Viewer

The Dependency Viewer tool window opens automatically once the analysis is finished and displays the results. To open the tool window manually, go to `View | Tool Windows | Dependency Viewer` in the main menu but make sure to run the analysis first.

Dependency Viewer consists of the following areas:

* The toolbar at the top of the tool window. Use these [buttons](#toolbar1) to filter dependencies.

* The Analyzed Code pane in the left part of the tool window contains the project tree. Selecting an item for which you want to find dependencies opens the Parent Code pane.

* The Parent Code pane on the right shows the items on which your selection depends.

* The Usage pane in the lower part of the tool window opens when you select an item in the Parent Code pane.

![Analyzing backward dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/backward-dependencies-animation.animated.gif)

### Analyzed Code toolbar buttons

| Item | Tooltip and Shortcut | Description |
| --- | --- | --- |
| ![Close](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.close.svg)  | Close | Close the current tab of the tool window. |
| ![rerun](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.rerun.svg)   | Rerun `Ctrl+F5` (Windows), `⌘ R` (macOS), `⌃ F5` (IntelliJ IDEA Classic (macOS)), `⌘ R` (macOS System Shortcuts), `Ctrl+F5` (XWin), `Ctrl+F5` (GNOME), `Ctrl+5` (KDE), `Ctrl+F5` (Emacs), `Ctrl+F5` (Sublime Text), `⌘ R` (Sublime Text (macOS)), `Ctrl+F5` (NetBeans), `Ctrl+Alt+R` (Visual Studio), `⌘ ⌥ R` (Visual Studio (macOS)), `Ctrl+F5` (Eclipse), `Ctrl+F5` (Eclipse (macOS)) | Rerun the dependency analysis in the same tab. |
| ![Flatten Packages](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.objectBrowser.flattenPackages.svg)  | Flatten Packages | Display all packages as a single-level tree view. |
| ![Show Files](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.fileTypes.unknown.png) | Show Files | Display files on the Analyzed Code and Parent Code panes. Otherwise, both panes display only packages. |
| ![Show Modules](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.actions.groupByModule.png)  | Show Modules | Display items under the corresponding modules in the tree view. Otherwise, project items are displayed under their packages.  |
| ![Flatten Modules](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.objectBrowser.flattenModules.svg) | Flatten Modules | Arrange items in the tree by user-defined module groups. |
| ![Group By Scope Type](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.actions.groupByTestProduction.svg) | Group by Scope Type | Group items in the tree by scope (production, test, libraries, and so on). |
| ![Filter](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.filter.svg)  | Show Illegals Only | Display only illegal and invalid dependencies. |
| ![Mark Illegal](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.actions.lightning.svg)  | Mark Illegal | Mark the selected dependency as illegal. |
| ![Settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.settings.svg) | Edit Rules | [Define rules](#validate-dependencies) for the dependencies analysis. |
| ![Export to Text File](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.export.svg) | Export to Text File | Export the results of the analysis to a text file or copy them to the clipboard.  |

## Validate dependencies

When analyzing dependencies, you might need to exclude some of them from the analysis process. You can do that using the Validate Dependencies option.

Procedure:

1. On the Dependency Viewer toolbar, click the ![Edit Rules](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.settings.svg) Edit Rules button.

In the dialog that opens, declare the rules that describe invalid and valid dependencies.

2. Click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg) in the required section of the dialog depending on the rule that you want to create.

Deny usages of:

1.  From the Deny usages of list, select the dependencies that will be recognized as invalid.

2.

From the in list, select the scope of files in which the selected usages will be treated as invalid.

If the necessary scopes are not created yet, click ![the Add scope (Insert) icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and [define new scopes](configuring-scopes-and-file-colors.html#creating-a-new-custom-scope) in the dialog that opens.

Allow usages of:

1.  From the Allow usages of list, select the dependencies that will be recognized as valid.

2.

From the only in list, select the scope of files in which the selected usages will be treated as valid. These usages will be valid only in case they are used in this scope.

If the necessary scopes are not created yet, click ![the Add scope (Insert) icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and [define new scopes](configuring-scopes-and-file-colors.html#creating-a-new-custom-scope) in the dialog that opens.

3. Select the Skip import statements checkbox if you want to ignore references in the import statements.

4. Apply the changes and close the dialog.

![the Dependency Validation dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/dependency-validation.png)

Click ![the Rerun button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.rerun.svg) on the [Dependency viewer toolbar](#dependency-viewer) to rerun the analysis with the new rules.

## See also

### Procedures

[Module dependencies](working-with-module-dependencies.html) [Module dependency diagrams](project-module-dependencies-diagram.html) [Dependency Structure Matrix](dsm-analysis.html)

