Semantic version and version range support in gradle

Hello.

Currently we use the following approach in maven https://github.com/barchart/barchart-version-tester https://github.com/barchart/barchart-version-tester/wiki https://github.com/barchart/barchart-version-tester/wiki/Version-Policy

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

and which boils down to * use osgi spec for “semantic version” http://www.osgi.org/wiki/uploads/Links/SemanticVersioning.pdf * use maven/aries version plugin https://github.com/apache/aries/tree/trunk/versioning * use bnd to produce osgi manifests http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

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.

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

configurations.all {
  resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    if (details.requested.name == 'groovy-all') {
      details.useTarget group: details.requested.group, name: 'groovy', version: details.requested.version
    }
  }
    incoming.resolutionResult.allDependencies { DependencyResult dependencyResult ->
    if (!SemanticVersion.isMatch(dependencyResult.requested.version) || !SemanticVersion.isMatch(dependencyResult.selected.id.version)) {
      return
    }
      def requested = new SemanticVersion(dependencyResult.requested.version)
    def selected = new SemanticVersion(dependencyResult.selected.id.version)
      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.

Luke:

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

Any update on your trials?