Slackbot
02/21/2023, 6:52 PMVampire
02/21/2023, 6:57 PMJendrik Johannes
02/21/2023, 7:20 PMwithDependencies
hook.
As usual, I have an example 😉 This checks that there are no versions defined directly on dependencies:
https://github.com/jjohannes/gradle-project-setup-howto/blob/main/gradle/plugins/d[…]/main/kotlin/org.example.dependency-analysis-project.gradle.ktsRyan Schmitt
02/21/2023, 7:30 PMRyan Schmitt
02/21/2023, 7:31 PMwithDependencies
hook and the resolutionStrategy
hook run in a defined order? (edit: does it even matter?)Vampire
02/21/2023, 7:51 PMVampire
02/21/2023, 7:53 PMRyan Schmitt
02/21/2023, 8:02 PMRyan Schmitt
02/21/2023, 8:05 PMwithDependencies
runs before the configuration participates in dependency resolution, and therefore it runs before any resolutionStrategy
.Vampire
02/21/2023, 8:05 PMJendrik Johannes
02/22/2023, 7:09 AMYes that's correct.runs before the configuration participates in dependency resolution, and therefore it runs before anywithDependencies
.resolutionStrategy
withDependencies
directly checks what is declared and also allows you to add additional dependencies "lat minute" (i.e. right before the dependency resolution starts). This is what it was mainly introduced for.
The resolutionStrategy
things work on the "resolution result" and are usually for modifying that result "last minute" (i.e. after all resolution was done, but right before it is passed to a task etc.)
For doing analysis on the "resolution result", I would usually do that in a task (or in an additional doFirst() of an existing task). For this I would look at the result in Configuration.incoming.resolutionResult
. But I think that's not what you need/want in this case.
I also think just looking at the declared dependencies in withDependencies
is cheap enough to always do it. As there is no dependency resolution or anything going on. You just look at the "plain data" put into the build scripts. But maybe there is a measurable impact in very large builds that can be an issue. I would just give it a try.Jendrik Johannes
02/22/2023, 7:13 AM