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

**URL:** <https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158>\
**Category:** Old Forum Archive\
**Created:** [December 9, 2011, 7:52pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158 "2011-12-09T19:52:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbjarland1](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mbjarland1](https://discuss.gradle.org/u/mbjarland1)\
**Post date:** [December 9, 2011, 7:52pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/1 "2011-12-09T19:52:00Z")

</div>

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

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

```

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

```gradle
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.:

```gradle
"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.

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [December 9, 2011, 10:14pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/2 "2011-12-09T22:14:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![mbjarland1](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mbjarland1](https://discuss.gradle.org/u/mbjarland1)\
**Post date:** [December 9, 2011, 10:20pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/3 "2011-12-09T22:20:00Z")

</div>

Thanks! Will give that a shot first thing tomorrow…

---

<div class="post-metadata">

**Author:** ![cjtkirk](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cjtkirk](https://discuss.gradle.org/u/cjtkirk)\
**Post date:** [May 3, 2013, 2:42am UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/4 "2013-05-03T02:42:00Z")

</div>

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()}"

} ``

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 3, 2013, 3:29am UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/5 "2013-05-03T03:29:00Z")

</div>

Starting from ‘Configuration’ in the [Gradle Build Language Reference](http://gradle.org/docs/current/dsl/index.html), you’ll eventually get to the Javadoc for ‘ResolvedArtifact’, which has the answer.

---

<div class="post-metadata">

**Author:** ![cjtkirk](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cjtkirk](https://discuss.gradle.org/u/cjtkirk)\
**Post date:** [May 3, 2013, 4:59pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/6 "2013-05-03T16:59:00Z")

</div>

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()

``

---

<div class="post-metadata">

**Author:** ![cjtkirk](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cjtkirk](https://discuss.gradle.org/u/cjtkirk)\
**Post date:** [May 3, 2013, 5:01pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/7 "2013-05-03T17:01:00Z")

</div>

Ahhhh nevermind.

getClassifier is the method to Interface ModuleVersionIdentifier and the group!

Thanks for teaching me to fish!

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 3, 2013, 5:03pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/8 "2013-05-03T17:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cjtkirk](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cjtkirk](https://discuss.gradle.org/u/cjtkirk)\
**Post date:** [May 3, 2013, 5:07pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/9 "2013-05-03T17:07:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 3, 2013, 6:26pm UTC](https://discuss.gradle.org/t/map-dependency-instances-to-file-s-when-iterating-through-a-configuration/7158/10 "2013-05-03T18:26:00Z")

</div>

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