/commands/gradle/gradle-dependencies
gradle dependencies --configuration runtimeClasspath: show the dependency tree
- tool
- Gradle
- versions
- Gradle 7 – 9
- os
- any
./gradlew dependencies prints the dependency tree of a project for every configuration; add --configuration runtimeClasspath (or compileClasspath, testRuntimeClasspath) to see only the one you care about. In a multi-project build, prefix the task with the project path: ./gradlew :app:dependencies. To find out why a specific version ended up in the tree, use ./gradlew dependencyInsight --dependency NAME.
Usage
./gradlew dependencies # root project, all configurations
./gradlew :app:dependencies --configuration runtimeClasspath # one module, one configuration
./gradlew :app:dependencyInsight --dependency guava --configuration compileClasspath
./gradlew :app:dependencies --configuration runtimeClasspath > deps.txtWithout :app:, Gradle runs the task in the root project only, which in many builds has no dependencies at all.
Reading the tree
| Marker | Meaning |
|---|---|
| +--- and \--- | A child and the last child of a node |
| 1.2.0 -> 1.3.1 | Requested 1.2.0, conflict resolution selected 1.3.1 |
| (*) | Subtree already shown earlier; omitted |
| (c) | A dependency constraint, not a dependency |
| (n) | Not resolved (the configuration cannot be resolved, such as implementation itself) |
| FAILED | Gradle could not resolve this module (check repositories and the version) |
Configurations worth knowing
| Configuration | Contains |
|---|---|
| compileClasspath | What the main code compiles against (implementation + compileOnly + api) |
| runtimeClasspath | What the application runs with (implementation + runtimeOnly + api) |
| testCompileClasspath | What tests compile against |
| testRuntimeClasspath | What tests run with |
| annotationProcessor | Annotation processors for javac |
implementation and api are declaration buckets and cannot be resolved; query the *Classpath configurations instead. For a browsable HTML report, run ./gradlew build --scan or apply the project-report plugin and run htmlDependencyReport.
Find out why a version was chosen
dependencies shows the whole tree; dependencyInsight answers a question about one module. It prints the selected version, the reason for the selection (for example conflict resolution or a constraint), and every path that requested the module, with the version each path asked for:
./gradlew :app:dependencyInsight --dependency jackson-databind --configuration runtimeClasspath
./gradlew :app:dependencyInsight --dependency jackson-databind --single-path # one path only| Option | Effect |
|---|---|
| --dependency NAME | The module to explain; a partial name such as guava matches the group and name |
| --configuration NAME | The configuration to inspect; compileClasspath is the default with the Java plugin |
| --single-path | Show one path to the module instead of all of them |
| --all-variants | Describe all variants of the module, not only the selected one |
How conflicts are resolved
When two paths request different versions of the same module, Gradle considers all requested versions and selects the highest by default. That is why a library can end up newer than what you declared, shown as 1.2.0 -> 1.3.1. If a declaration uses strictly with a lower version, resolution fails instead of upgrading. To force a version on purpose, prefer a dependency constraint or a platform (BOM) over excluding transitive dependencies; constraints then appear in the tree with (c).
Typical uses
- A vulnerable transitive library: run
dependencyInsightfor it to find the direct dependency that brings it in, then upgrade that dependency or add a constraint. - NoSuchMethodError or ClassNotFoundException at run time: compare
compileClasspathandruntimeClasspath; a version that differs between them often explains the failure. - Reviewing a dependency upgrade: save the tree before and after (
> deps.txt) and diff the two files.
FAQ
Why does gradle dependencies show nothing for my project?
You probably ran it in the root project of a multi-project build, which often declares no dependencies. Run it for the module, such as ./gradlew :app:dependencies.
Why did Gradle pick a newer version than the one I declared?
When several versions of a module are requested anywhere in the graph, Gradle selects the highest one by default; the tree shows it as 1.2.0 -> 1.3.1. dependencyInsight lists who asked for which version.
How do I see the dependencies of the build script or plugins?
Use ./gradlew buildEnvironment. The dependencies task covers the project's configurations, not the classpath of the build script itself.