How to get dependencies programmatically

I want to get the final/resolved dependencies, in fact, a list of artifacts used in a given build (for example, “assembleDebug” in Android). How do I get that?

I ran into examples such as:

task dumpDependencies {
  doLast {
    def resolved = configurations.compileClasspath.resolvedConfiguration
    resolved.resolvedArtifacts.each {
      artifact-> println "Artifact: $artifact"
    }
  }
}

Above doesn’t work for Gradle 7.5 and I get the error:

Could not get unknown property ‘compileClasspath’ for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.

How do I accomplish what I need?

compileClasspath is more coming from Java projects or similar.
Pick the right configuration for Android and it will probably work.
Or if you just want to print it, just use the dependencies task, or look at a build --scan.

1 Like

Thankyou so much !!! I used a valid configuration like “debugRuntimeClasspath” and it worked!

1 Like