Semantic version and version range support in gradle

(Andrei Pozolotin) #1


Currently we use the following approach in maven

which takes care of semantic version and version range support that we need,

and which boils down to * use osgi spec for “semantic version” * use maven/aries version plugin * use bnd to produce osgi manifests

I can not find any obvious answer for * is there default semantic version support in gradle? * does gradle support version ranges for dependency resolution?

I would appreciate references to live projects using both features.

Thank you.

(Luke Daley) #2

There is no default semantic version support, but you can add it yourself quite easily.

configurations.all {
  resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    if ( == 'groovy-all') {
      details.useTarget group:, name: 'groovy', version: details.requested.version
    incoming.resolutionResult.allDependencies { DependencyResult dependencyResult ->
    if (!SemanticVersion.isMatch(dependencyResult.requested.version) || !SemanticVersion.isMatch( {
      def requested = new SemanticVersion(dependencyResult.requested.version)
    def selected = new SemanticVersion(
      if (requested.major != selected.major) {
      throw new Exception("Dependency $dependencyResult has a different selected major version than was requested")
  class SemanticVersion {
  int major
  int minor
  int patch
    SemanticVersion(String version) {
    (major, minor, patch) = version.split("\.")
    static boolean isMatch(String version) {
    version ==~ /\d+\.\d+\.\d+/

It would be great if someone turned that into a plugin.

Gradle does support version ranges, you can find info in the user guide.

(Andrei Pozolotin) #3


thanks for the idea. let me try to port our maven use case to gradle. I will report back. Andrei.

(Chris Doré) #4

Any update on your trials?