Skip to content

bitlap/intellij-sbt-dependency-analyzer

Repository files navigation

Sbt Dependency Analyzer for IntelliJ IDEA

Sbt Dependency Analyzer Logo

Build Status Plugin Version Plugin Downloads

English | 中文

⭐ Found this plugin useful? Please give it a Star on GitHub to show your support!

🚀 Overview

The Sbt Dependency Analyzer plugin for IntelliJ IDEA provides powerful visual tools to help you understand, manage, and troubleshoot your Sbt project's dependencies with ease. Gain clear insights into your library dependencies and their relationships, directly within your IDE.

Compatible with IntelliJ IDEA 2023.1 and later (Community Edition, Ultimate, and Android Studio).

✨ Key Features

  • Dependency Tree Visualization: View a hierarchical tree of all your project's dependencies.
  • Conflict Identification: Quickly spot and resolve version conflicts between libraries.
  • Dependency Search: Easily find specific dependencies across your project.
  • Inter-Module Dependency Analysis: Visualize how different modules in your project depend on each other.
  • JAR Size Indicators: See the size of dependency JARs to better manage your project's footprint.
  • Navigate to Declaration: Click on a user-defined dependency to jump directly to its declaration in build.sbt.
  • Dependency Exclusion (Experimental):
    • Select a transitive dependency to exclude it from a user-defined dependency.
    • Select a user-defined dependency to remove it entirely.
    • Available since plugin version 0.5.0-242.21829.142.

🛠️ Installation & Setup

  1. Install the Plugin: Go to Settings/Preferences > Plugins > Marketplace, search for "Sbt Dependency Analyzer", and install it.
  2. Automatic Setup: Upon first analysis, the plugin will automatically generate a project/sdap.sbt file if needed. This file adds the required addDependencyTreePlugin statement. Please do not modify or delete this file once created.
  3. Plugin Dependency: This plugin leverages the sbt-dependency-tree functionality, which is bundled with recent sbt versions (though not be enabled by default, sbt issue).

📖 Usage

Default Keyboard Shortcut: Ctrl + Shift + L (Windows/Linux) / Command + Shift + L (MacOS)

Simply open your Sbt project in IntelliJ IDEA and use the shortcut to generate and view the dependency analysis.

Dependency Analysis View The interactive dependency graph provides a clear overview of your project's structure.

⚙️ Configuration

Fine-tune the plugin's behavior and potentially speed up analysis via Settings/Preferences > Tools > Sbt Dependency Analyzer:

Plugin Settings Panel

  • File Cache Timeout: Adjust how long (in seconds) the plugin uses cached dependency graph files (.dot) before re-running the dependencyDot command. (Default: 3600).
  • Organization: Predefine your project's organization value here to avoid the plugin needing to query sbt for it.
  • Disable Scopes: Improve analysis speed by disabling dependency scopes (e.g., Test, Provided) you are not interested in.

These settings are stored per IntelliJ project in .idea/bitlap.sbt.dependency.analyzer.xml. Deleting this file will reset settings and clear the cache.

❗ Troubleshooting

Issue: "Caused by: java.io.IOException: Could not create lock for ..."

This error can occur due to conflicts between the plugin's use of the sbt shell and IntelliJ IDEA's internal project reload/build mechanisms.

  • Solution: Use the sbt shell within IntelliJ IDEA for reloading (sbt reload) or building (sbt compile) your project, instead of the IDE's built-in buttons. Using SBT Shell for reload and compile

Issue: Cannot analyze dependencies between modules

The plugin may fail to correctly parse inter-module dependencies if it cannot determine the project organization.

  • Solution: Ensure the plugin knows your project's organization by either:
    1. Setting the Organization value in the plugin's settings.
    2. Defining the organization setting in your build.sbt globally using ThisBuild / organization or inThisBuild(...).

Note: Submodules not declared within the dependsOn clause of the root project will not be parsed.

🔍 Technical Details

  1. The plugin executes several sbt commands (organization, moduleName, dependencyDot, reload, update) to gather dependency information. Significant optimizations are in place to minimize the number and impact of these commands.
  2. The plugin has replicated the Kotlin code from the intellij-community project on the UI and compiles it using the kotlin-plugin.

🤝 Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on GitHub.

🙏 Acknowledgments

JetBrains Support: This project is developed using JetBrains IntelliJ IDEA. We extend our gratitude to JetBrains for providing a free license, which significantly supports its development.

IntelliJ IDEA logo.