Map Dependency instances to File(s) when iterating through a configuration?

So I know I can iterate through the artifact files in a configuration by:

configurations.myconf.each { f ->
    println "FILE: $f"
  }

and I can iterate through the dependency objects via something like:

configurations.myconf.allDependencies.withType(ExternalModuleDependency).each { d ->
    println "group: ${d.group}, name: ${d.name}, version: ${d.version}"
  }

but what I want to do is to map specific dependencies to the files they pulled in. I.e.:

"org.codehaus.groovy:groovy:1.7.10" -->
  .gradle/caches/artifacts-4/org.codehaus.groovy/groovy/738b4649a184de25c9cf3629f299f356/jars/groovy-1.7.10.jar

This seems like a trivial thing, but I have failed to figure this out. Any help much appreciated.

You should be able to do this by iterating over ‘configurations.myconf.resolvedConfiguration.resolvedArtifacts’.

Check out dsl:org.gradle.api.artifacts.Configuration

Thanks! Will give that a shot first thing tomorrow…

Have the exact same question.

The code below shows the name and file as desired.

Thanks!

I also want the dependency GROUP.

Does not seem to be in the api here.

Any thoughts on how to get that (since the same file name may be in another dependency group.

configurations.myconf.resolvedConfiguration.resolvedArtifacts.each { dep ->

println " Name=${dep.getName()} File=${dep.getFile()}"

}

Starting from ‘Configuration’ in the Gradle Build Language Reference, you’ll eventually get to the Javadoc for ‘ResolvedArtifact’, which has the answer.

I do see the API for ResolvedArtifact (listed below), and the dependency name (and type) are here, but not group for some reason.

I have a workaround in my code, but wanted to learn more so thought I would ask.

Methods

String getClassifier()

String getExtension()

File getFile()

ResolvedModuleVersion getModuleVersion() Returns the module which this artifact belongs to. String getName()

ResolvedDependency getResolvedDependency() Deprecated.

An artifact can belong to multiple dependencies. Use getModuleVersion() instead. String getType()

Ahhhh nevermind.

getClassifier is the method to Interface ModuleVersionIdentifier and the group!

Thanks for teaching me to fish!

According to the Javadoc, it’s ‘resolvedArtifact.moduleVersion.id.group’.

Yes.

Again, thank you so much not just for answering this question but more importantly how to navigate the gradle DSL and API.

Gradle is an impressive product not just in WHAT it does but HOW it does it (world-class documentation, rapid releases, etc).

Thanks!

Thanks for the praise. Still working on the world-class documentation. :slight_smile: