Dump dependencies flat and for a specific package

I know how to get gradle to dump the depencies of an Android project with ./gradlew app:dependencies but what I want is:

  1. For a specific build, not just all of them.
  2. in a flat format, not a tree I need to parse
  3. For a specific package, not just one.

I would highly recommend you try creating a build scan for this, which will show a filterable dependency tree like this one.

Two caveats, though:

  1. The build scan isn’t exportable unless you’re a Gradle Enterprise customer
  2. I’m not perfectly clear what you mean by “specific package”. Do you mean specific library dependency or specific Java package?


Thanks, I will look up build scan and whatnot. I would like to have a flat list of dependencies too, rather than in a tree.

Re the package, I mean like for com.facebook.fresco:imagepipeline-okhttp3:1.0.1. I want to find all the dependencies of that, that is including transitive ones too.

Will this work for you? I used compile configuration as an example.

configurations.compile.allDependencies.each { Dependency d->
  println "${d.group}:${d.name}:${d.version}"

Very rough-and-ready, and only prints to the console, but should give you an idea where to start.


I tried in the root build.gradle of an android project:

task foo { configurations.compile.allDependencies.each { Dependency d-> println "${d.group}:${d.name}:${d.version}" } }

But this errors with:

* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not get unknown property 'compile' for configuration container.

You need to replace cmopile with a valid configuration name. Your root project will probably contain no configurations. Try the same in the app subproject. Valid configuration names are the same as which would be returned by app:dependencies

Thanks, will try.

This code sample, it will only print out the first level of dependencies right, not the transitive ones as well.

Is this useful (using junit as an example instead of imagepipeline-okhttp3)?

dependencies {
    compile 'org.spockframework:spock-core:+'

task dumpDepsOfInterest {
    doLast {
        def componentOfInterest = configurations.compile.incoming.resolutionResult.allComponents.find { comp ->
            comp.moduleVersion.group == 'junit' && comp.moduleVersion.name == 'junit'
        if( componentOfInterest != null ) {
            println componentOfInterest.moduleVersion

            def deps = []
            deps.addAll( componentOfInterest.dependencies )

            while( deps.size() > 0 ) {
                def currDep = deps.pop()
                if( currDep instanceof ResolvedDependencyResult ) {
                    println currDep.selected.moduleVersion
                    deps.addAll( currDep.selected.dependencies )
                } else {
                    throw new GradleException( "Could not resolve ${currDep.requested}" )
        } else {
            throw new GradleException( "Could not find component of interest" )

Dependecy tree:

$ ./gradlew dependencies --configuration=compile -q
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
\--- org.spockframework:spock-core:+ -> 1.1-groovy-2.4
     +--- org.codehaus.groovy:groovy-all:2.4.9
     \--- junit:junit:4.12
          \--- org.hamcrest:hamcrest-core:1.3

Task output:

$ ./gradlew dumpDepsOfInterest -q

Oh awesome! I modified it slightly and works for me great! Thanks!