Resolution Strategy for first level dependency only

ResolutionStrategy can be used to fine-tune the dependencies.

I’d like to write a task to know if my project is releasable. One of the prerequisite is that all of its first-level dependencies are already released, with the same RELEASE_NAME.
In other words, if my component FOO must be released with the RELEASE_NAME name, I need to find RELEASE_NAME versions of all its first level dependencies.

I thought about using resolutionStrategy for this

configurations.checkRelease.resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    if ( **first level dependency** ) {
        details.useVersion "${project.RELEASE_NAME}"

And then resolve the checkRelease configuration, and see if it fails or not to find the dependencies

Is there a way to apply this only to first level dependencies ?
Do you see another way to achieve my check ?

Something like the following should work. This is pretty much what I do in the versions plugin except that I use a lenient configuration, whereas the below will break the build (as desired).

configurations.each { configuration ->
  def config = configuration.copyRecursive().setTransitive(false)
  config.resolutionStrategy { ... }
1 Like