# How to apply plugin at the Execution Phase?

**URL:** <https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574>\
**Category:** Plugin Portal\
**Created:** [April 28, 2019, 8:37am UTC](https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574 "2019-04-28T08:37:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamposh93](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@pamposh93](https://discuss.gradle.org/u/pamposh93)\
**Post date:** [April 28, 2019, 8:37am UTC](https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574/1 "2019-04-28T08:37:38Z")

</div>

Hi,  
I want my plugin to return all the dependencies, I tried project.getConfigurations().getByName(“compileClasspath”).getAllDependencies() but no dependencies are being returned. Is there any way to get these dependencies ?

---

<div class="post-metadata">

**Author:** ![ljacomet](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ljacomet/32/11907_2.png) [@ljacomet](https://discuss.gradle.org/u/ljacomet)\
**Post date:** [April 28, 2019, 11:03am UTC](https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574/2 "2019-04-28T11:03:49Z")

</div>

First of all a method like `Configuration.getAllDependencies()` will only return declared dependencies in this configuration and the ones it extends from.  
It will not cause resolution to happen and thus will not include transitive dependencies.  
Have a look at the [Configuration DSL documentation](https://docs.gradle.org/5.4.1/dsl/org.gradle.api.artifacts.Configuration.html) for more details.

Also what do you mean by “return all the dependencies”?

Gradle, by design, has different configurations for different purposes that will, by definition, represent potentially a different set of declared _and_ transitive dependencies.

---

<div class="post-metadata">

**Author:** ![pamposh93](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@pamposh93](https://discuss.gradle.org/u/pamposh93)\
**Post date:** [April 28, 2019, 6:21pm UTC](https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574/3 "2019-04-28T18:21:15Z")

</div>

# build.gradle

dependencies {  
implementation ‘org.apache.commons:commons-math3:3.6.1’  
testImplementation ‘junit:junit:4.12’  
}  
These are the dependencies declared in my build.gradle file. I want my plugin to fetch all these dependencies and their transitive dependencies,

±-- org.apache.commons:commons-math3:3.6.1  
— junit:junit:4.12  
— org.hamcrest:hamcrest-core:1.3

Configuration.getAllDependencies() is not returning me any dependency, I thought if we could apply the plugin in execution phase we might get dependencies.

If there is a better approach to do this kindly suggest.

---

<div class="post-metadata">

**Author:** ![ljacomet](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ljacomet/32/11907_2.png) [@ljacomet](https://discuss.gradle.org/u/ljacomet)\
**Post date:** [April 29, 2019, 8:11am UTC](https://discuss.gradle.org/t/how-to-apply-plugin-at-the-execution-phase/31574/4 "2019-04-29T08:11:39Z")

</div>

Your plugin code most likely executes `configuration.getAllDependencies()` at the time it is applied, but that means the `dependencies` block has not been applied yet.

You probably want to have your dependency related action either linked to a task that needs to be invoked or can be wired as a dependency of other tasks or you can use the `project.afterEvaluate` callback for performing your action always.

The right answer to your problem really depends on what you are trying to achieve.
