Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle dependency versions '+' sign

Tags:

gradle

I'm trying to understand how Gradle handles dependency versions with a '+' sign as seen in example 8.1 here: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html

testCompile group: 'junit', name: 'junit', version: '4.+

The documentation states that this will get a version of junit >= 4.0. How would a get a version of a dependency greater than (or equal to), say, 5.10? Would it be 5.10+ or 5.1+? The former seems to not work correctly, but the latter does. How would I get a dependency greater than or equal to 1.22? 1.2+? In this scenario, if version 1.21 exists and is the latest version, I would like to fail, since I want greater than or equal to 1.22, but 1.2+ will look for >= 1.20. How can I specify this? Is this possible? I can't seem to find more documentation on it.

Edit: I tend to think of it as 1.2+ is equivalent to 1.2([0-9]+). Is this the correct way of thinking?

like image 645
Nick Russell Avatar asked Feb 20 '13 12:02

Nick Russell


People also ask

How do I know if Gradle dependency has new version?

Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.

What does -> mean in Gradle dependencies?

It means that dependency graph contains multiple dependencies with the same group and module but different versions for e.g. org.

What does C mean in Gradle dependency tree?

Sadly, the Gradle docs do not cover this topic so it is a bit confusing. Issuing gradlew dependencies | tail shows a legend explaining the meaning of the printed suffixes. (c) - dependency constraint (*) - dependencies omitted (listed previously) (n) - Not resolved (configuration is not meant to be resolved)


2 Answers

In this scenario, if version 1.21 exists and is the latest version, I would like to fail, since I want greater than or equal to 1.22, but 1.2+ will look for >= 1.20. How can I specify this? Is this possible?

I don't think there is any documentation about this, but since Gradle originally used Ivy under the hood for all its dependency management functionality, I took a look at the Ivy documentation regarding dynamic versions:

http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html

It has only slightly more than the Gradle documentation. I tried experimenting in Gradle with Ivy-style version ranges:

compile group: 'log4j', name: 'log4j', version: '[1.2.12,1.2.17]' 

and surprisingly it seems to sometimes work depending on what the version range is. In the example above it resolves to 1.2.17.

I know this doesn't fully address your questions (which I am curious about too) but hopefully it provides a bit of information for you.

like image 177
Dave L. Avatar answered Oct 04 '22 04:10

Dave L.


I think the issue is that you are incorrectly thinking of the "+" in terms of regex. It isn't meant to be read as a regex expression element ("one or more numeric characters"), but rather as "the latest available version where each of the leading SEMVER components match the pattern provided". References on why this is not preferred to even use this notation can be found at: http://central.sonatype.org/articles/2014/Oct/28/enforcing-valid-dependency-versions/

like image 27
Kevin Welker Avatar answered Oct 04 '22 03:10

Kevin Welker