Gradle Plugin: Get runtime dependencies

Is there a way to get all dependent projects in the runtime configuration during configuration phase?

I’m writing a gradle plugin and I have to define some task dependencies on dependent projects of my project where the plugin is applied. To achieve that, I want do get all dependencies of the “runtime” configuration with the following code:

dependencies = p.getConfigurations().getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME).getAllDependencies().withType(DefaultProjectDependency.class);

The problem: When my plugin is applied, the returned list is always empty. (which is not correct, there are a lot of runtime dependencies) I also tried to write a BuildListener and access the dependencies in the “projectsEvaluated” method, with no success.

If I access the dependencies in the “buildFinished” method, I get all dependencies correctly! But thats of course too late.

Is there a way to access the runtime dependencies at a moment where its still possible to define my task dependencies of my build? (configuration phase or directly ‘after’ configuration?)

Thanks for any advice.

You probably iterated over the returned set with an each {} which will traverse the collection eagerly.

Use all {} instead, which will apply the given closure to every dependency that’s in it now or added later.

Thanks for your answer, you are probably right.

I solved my problem in another way. The problem was in our build file of this project, because these runtime dependencies were also defined in the “projectsEvaluated” method. And because I used “projectsEvaluated” in my plugin too, the order of execution was undefined. (respectively the dependencies were defined after my plugin’s code was executed)

We solved our problem by defining the depencencies not inside the “projectsEvaluated { }”.