131

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.

spaaarky21
  • 6,524
  • 7
  • 52
  • 65
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212

9 Answers9

141

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

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • actually, I tried that....I realized my dependencies are in my lowest level subproject(ie. the one that everyone else depends on) and not in the main project...not sure if that is bad or good at this point. – Dean Hiller Sep 05 '12 at 21:15
  • You need to run the command for the particular project that you are interested in. Typically, you'd cd into the project directory and run the command from there. – Peter Niederwieser Sep 05 '12 at 21:22
  • 12
    This doesn't work on all type of projects. I am getting 'No configurations' and need to run something else to get this going. Hopefully one day gradle will handle this so the actual commands are going to be predicatble. – R. van Twisk Jan 07 '14 at 20:04
  • Mind to share some details? Sounds like a third-party plugin that does its own thing. Or perhaps a build script doesn't get things right. – Peter Niederwieser Jan 07 '14 at 20:12
  • 2
    Is there a flag for including transitive dependencies? – BitPusher Aug 07 '14 at 22:05
  • 1
    They are included automatically. – Peter Niederwieser Aug 07 '14 at 22:46
133

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
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
41

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
user1707414
  • 3,833
  • 2
  • 18
  • 19
  • 2
    More details about that approach in the blog post: https://solidsoft.wordpress.com/2014/11/13/gradle-tricks-display-dependencies-for-all-subprojects-in-multi-project-build/ – Marcin Zajączkowski Jun 26 '15 at 11:43
  • 9
    You can add this to your `~/.gradle/init.gradle` rather than adding it to every build. Then it works for all projects on your machine, but only for you. – derekv Nov 11 '15 at 18:06
26

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
icyerasor
  • 4,973
  • 1
  • 43
  • 52
20

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
Renato
  • 12,940
  • 3
  • 54
  • 85
8
gradlew -q :app:dependencies > dependencies.txt

Will write all dependencies to the file dependencies.txt

abitcode
  • 1,420
  • 17
  • 24
4

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

./gradlew app:dependencies --configuration compile
pscl
  • 3,322
  • 25
  • 29
1
  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.
lazylead
  • 1,453
  • 1
  • 14
  • 26
-1

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.

Ryan Shillington
  • 23,006
  • 14
  • 93
  • 108
  • 1
    but it only analyzes the targets that ran not the full graph :(. – Dean Hiller May 07 '19 at 16:47
  • True! It depends on what you want. I think dependencies for just the targets that ran is even more powerful. It'll tell you why one set of commands seems to do the wrong thing. – Ryan Shillington May 07 '19 at 18:54
  • I really want the full graph so I don't have to test out each node tbh....that gets quite tedious....even if it takes a while, it's more useful but I don't see a way to do it in the newer versions. – Dean Hiller May 07 '19 at 22:43