# Event/Action for when a dependency is downloaded by Gradle

**URL:** <https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842>\
**Category:** Old Forum Archive\
**Created:** [September 4, 2014, 12:21pm UTC](https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842 "2014-09-04T12:21:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Buletza](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jared\_Buletza](https://discuss.gradle.org/u/Jared_Buletza)\
**Post date:** [September 4, 2014, 12:21pm UTC](https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842/1 "2014-09-04T12:21:00Z")

</div>

Is there an event/or action I can hook up to, in order to do something when Gradle downloads a dependency? I see the listeners on the project for things like DependencyResolution… but I don’t see a dependencydownloaded or anything like that.

I know that I can access all the dependencies in a configuration, and I know I can access all the files of a configuration, Is there an easy way a to know which file came from which dependency?

Thank you.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [September 4, 2014, 10:05pm UTC](https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842/2 "2014-09-04T22:05:00Z")

</div>

For any given configuration you can ask it for the files of any given dependency. So getting the information I believe you want would simply involve iterating over this information. Try adding the following task

task dependencyFiles \<\< {

configurations.compile.dependencies.all {

println "${it}: "

println configurations.compile.files(it).collect { [it.name](http://it.name) }

}

}

It should produce output that looks something like:

DefaultExternalModuleDependency{group=‘org.codehaus.jackson’, name=‘jackson-mapper-asl’, version=‘1.9.12’, configuration=‘default’}:

[jackson-mapper-asl-1.9.12.jar, jackson-core-asl-1.9.12.jar]

---

<div class="post-metadata">

**Author:** ![Jared\_Buletza](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jared\_Buletza](https://discuss.gradle.org/u/Jared_Buletza)\
**Post date:** [September 5, 2014, 5:47am UTC](https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842/3 "2014-09-05T05:47:00Z")

</div>

Thanks for the information… While it is useful, its not quite what I’m looking for. The method you just described will give me all of the (transitive) files from a dependency, but not the group of these dependencies, you still also only have the group of the first level dependency.

What I really want to do is to process a downloaded dependency file a single time (the first time its is downloaded into the cache). So, the second time you run a build, there would be no processing since the artifact was already local.

example: I have a really large archive file as a dependency, and I need to access the contents of that file in a build. I don’t want to have to unarchive it every build… I want to unarchive it once and put the contents into a local cache. If I could attach a listener to the act of downloading a dependency, it would solve this problem for me.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [September 5, 2014, 3:28pm UTC](https://discuss.gradle.org/t/event-action-for-when-a-dependency-is-downloaded-by-gradle/5842/4 "2014-09-05T15:28:00Z")

</div>

It seems like this kind of thing is more appropriately solved using incremental build support. I would simply add a task that did the unpacking of this artifact. The only issue I see with this approach is that your “cache” would be wiped out whenever you did a ‘clean’ but you could probably avoid that by putting the output of your task outside your build directory.
