What is the Gradle artifact dependency graph command?

Gradle

Gradle Problem Overview


I read this comment in the Gradle docs:

To deal with problems due to version conflicts, reports with dependency graphs
are also very helpful. Such reports are another feature of dependency management.

I have some kind of jar being brought in but I need to figure out where it is coming from. Normally I would just globally exclude it, but I need some information on the hierarchy here. How do I get this information like I can from Ivy and Maven?

NOT to mention that someone is bringing Hibernate jars (a lot) in to my jar list and I really want to know who since I am not using Hibernate and try to cut out that dependency.

Gradle Solutions


Solution 1 - Gradle

The command is gradle dependencies, and its output is much improved in Gradle 1.2. (You can already try 1.2-rc-1 today.)

Solution 2 - Gradle

Ah, since I had no dependencies in my master project, "gradle dependencies" only lists those and not subproject dependencies so the correct command ended up being

 gradle :<subproject>:dependencies

so for me this was

 gradle :master:dependencies

Solution 3 - Gradle

If you want to see dependencies on project and all subprojects use in your top-level build.gradle:

subprojects {
	task listAllDependencies(type: DependencyReportTask) {}
}

Then call gradle:

gradle listAllDependencies

Solution 4 - Gradle

If you got a lot configurations the output might be pretty lengthy. To just show dependencies for the runtime configuration, run

gradle dependencies --configuration runtime

Solution 5 - Gradle

If you want recursive to include subprojects, you can always write it yourself:

Paste into the top-level build.gradle:

task allDeps << {
    println "All Dependencies:"
    allprojects.each { p ->
        println()
        println " $p.name ".center( 60, '*' )
        println()
        p.configurations.all.findAll { !it.allDependencies.empty }.each { c ->
            println " ${c.name} ".center( 60, '-' )
            c.allDependencies.each { dep ->
                println "$dep.group:$dep.name:$dep.version"
            }
            println "-" * 60
        }
    }
}

Run with:

gradle allDeps

Solution 6 - Gradle

gradlew -q :app:dependencies > dependencies.txt

Will write all dependencies to the file dependencies.txt

Solution 7 - Gradle

For those looking to debug gradle dependencies in react-native projects, the command is (executed from projectname/android)

./gradlew app:dependencies --configuration compile

Solution 8 - Gradle

  1. To list all dependencies: gradle yourmodule:dependencies > dep.txt.
  2. In case if you need to list places/roots where a particular problematic dependency came to your project: gradle -q dependencyInsight --dependency commons-io --configuration runtimeClasspath, where commons-io is your dependency.

Solution 9 - Gradle

In recent versions of Gradle (ie. 5+), if you run your build with the --scan flag, it tells you all kinds of useful information, including dependencies, in a browser where you can click around.

gradlew --scan clean build

It will analyze the crap out of what's going on in that build. It's pretty neat.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDean HillerView Question on Stackoverflow
Solution 1 - GradlePeter NiederwieserView Answer on Stackoverflow
Solution 2 - GradleDean HillerView Answer on Stackoverflow
Solution 3 - Gradleuser1707414View Answer on Stackoverflow
Solution 4 - GradleicyerasorView Answer on Stackoverflow
Solution 5 - GradleRenatoView Answer on Stackoverflow
Solution 6 - GradleabitcodeView Answer on Stackoverflow
Solution 7 - GradlepsclView Answer on Stackoverflow
Solution 8 - GradlelazyleadView Answer on Stackoverflow
Solution 9 - GradleRyan ShillingtonView Answer on Stackoverflow