Niranjan
Niranjan

Reputation: 2921

How to resolve dependency using wild card while generating pom.xml from gradle build

I am using Gradle (v2.0) in my application. For one of the dependencies I am using wild card in the version (see the code below)

build.gradle

ext {
  my_utils_version = "1.0+"
}

dependencies {
  compile "com.demo.myapp:my-utils:${my_utils_version}"
}

I am generating POM from my gradle build using following piece of code

task writePom << {
  conf2ScopeMappings.mappings.remove(configurations.testCompile)
  conf2ScopeMappings.mappings.remove(configurations.testRuntime)
  pom {
  }.writeTo("$buildDir/libs/pom.xml")
}
assemble.dependsOn writePom

So, whenever Gradle generates the POM, it uses 1.0+ as the version for the dependency compile "com.demo.myapp:my-utils:${my_utils_version}". In the generated POM.xml, I see

<dependency>
  <groupId>com.demo.myapp</groupId>
  <artifactId>my-utils</artifactId>
  <version>1.0+</version>
  <scope>compile</scope>
</dependency>

Maven is not able to resolve version 1.0+. Maven requires [1.0) as its own wildcard versioning.

Could someone help me in resolving this issue? How can I tell Gradle to use [1.0) instead of 1.0+?

Upvotes: 2

Views: 3032

Answers (2)

Niranjan
Niranjan

Reputation: 2921

As per Peter Niederwieser, I should use notation [1.0,) as the version. This notation is understood by both Maven and Gradle.

ext {
       my_utils_version = "[1.0,)"
    }

    dependencies {
      compile "com.demo.myapp:my-utils:${my_utils_version}"
    }

This solved my problem. Since Peter did not reply this suggestion as an answer, I am doing that. So, the actual answer was given by Peter; not me :)

Thank you Peter for the help. It helped me saving a lot of time and got rid of another priority-1 issue in my application.

Upvotes: 0

Peter Niederwieser
Peter Niederwieser

Reputation: 123960

Gradle does support Maven's version range notation, so you can use [1.0) in the build script (although I'm not quite sure if Maven/Gradle allows to omit the upper bound).

Upvotes: 1

Related Questions