Search code examples
mavengradlesnapshotmaven-enforcer-plugin

Gradle equivalent of Maven Enforcer's RequireReleaseDeps


What would the Gradle equivalent of using the Maven Enforcer Plugin to prevent releases from pointing to snapshot dependencies be? Is this possible at all?

I would like to be able to prevent a release from happening if there's any snapshot dependency on the build. I know I could probably code my way through it but I was wondering if there was any "standard" or obvious way of doing it with gradle and I couldn't find anything on the web about it.

SOLUTION

Used resolution strategy as suggested by correct answer:

project.getConfigurations().all { config ->
    config.resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        //verifying that versions do not contain "SNAPSHOT"
        if (details.requested.version.contains("SNAPSHOT")) {
            throw new GradleException(sprintf("Using snapshot version of %s.%s", 
                [details.requested.group, details.requested.name]))
        }
    }
}

Solution

  • You can implement your own resolution strategy that will reject SNAPSHOT dependencies. Take a look at https://gradle.org/docs/current/userguide/dependency_management.html#sec:dependency_resolution to see how this works and what are your possibilities.