How to apply plugin at the Execution Phase?

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 ?

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 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.


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.

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.