The Griffon project has a Gradle plugin that’s capable of resolving custom BOM files in such a way that additional dependencies are added to well known configurations, such as compile and testCompile. This plugin uses the dependencies.incoming.beforeResolve mechanism and for the time being it works. However since Gradle 2.3 we have seen a warning appear, such as
Changed dependencies of configuration ':kiosk:compile' after it has been included in dependency resolution. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0. Use 'defaultDependencies' instead of 'beforeResolve' to specify default dependencies for a configuration.
Changed dependencies of parent of configuration ':kiosk:testCompile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of parent of configuration ':kiosk:testRuntime' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of parent of configuration ':kiosk:integrationTestCompile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of parent of configuration ':kiosk:runtime' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
The problem is that you’re adding dependencies to the :kiosk:compile configuration after the :kiosk:testCompile configuration has been resolved. This means that testCompile will not contain the added dependencies, even though it extends the compile configuration.
This is unlikely to be what you want, and is a fundamental problem with using beforeResolve for supplying additional dependencies, since it doesn’t fire when resolving child configurations. We didn’t change the way it works, but we recently added the warning about it.
To avoid the warning and make this more correct, you’ll need to modify the configuration earlier in the build, rather than relying on beforeResolve. I don’t have any suggestions on the best way to do this, off the top of my head, sorry.
Thank you for the info Daz.
Is there another lifecacle phase I can hook into to figure out what can be done? I was able to figure out the beforeResolve option after discussing with Peter N. close to a year ago.
Unfortunately, the only obvious place for a plugin to do this sort of work is in project.afterEvaluate. Improving this is one of the key objectives of the upcoming rule-based configuration model.
configurations are not resolved at a particular point in time in gradle. They are resolved when needed. So project.afterEvaluate should be fine if you havn’t used (resolved) any configurations at configuration time.
Can you point me to a Gradle project that uses your plugin and produces the warning messages you are seeing? I’d like to set up a test case for your plugin and go from there to find a viable solution.
I think the original problem can be reproduce if dependencies are updated earlier during the build. My workaround simply makes sure BOM dependencies are queried and processed as lat as possible.
I’d prefer if there was a better hook exposed by the Gradle API to modify dependencies before configurations are treated as immutable for performance reasons.
Got it. Any chance you can put together a minimal example on GitHub that reproduces the issue you were seeing? It would be much easier for us to extract the use case and the essence of the issue in order to work on an adequate fix.