Using dynamic versions
Until now, we have set a version for a dependency explicitly with a complete version number. To set a minimum version number, we can use a special dynamic version syntax, for example, to set the dependency version to a minimum of 2.1 for a dependency, we use a version value of 2.1.+. Gradle will resolve the dependency to the latest version after version 2.1.0, or to version 2.1 itself. The upper bound is 2.2. In the following example, we will define a dependency on a spring-context version of at least 4.0.x:
dependencies { compile 'org.springframework:spring-context:4.0.+' }
To reference the latest released version of a module, we can use latest.integration
as the version value. We can also set the minimum and maximum version numbers we want. The following table shows the ranges we can use in Gradle:
Range |
Description |
---|---|
|
We can use all versions greater than or equal to 1.0 and lower than or equal to 2.0 |
|
We can use all versions greater than or equal to 1.0 and lower than 2.0 |
|
We can use all versions greater than 1.0 and lower than or equal to 2.0 |
|
We can use all versions greater than 1.0 and lower than 2.0 |
|
We can use all versions greater than or equal to 1.0 |
|
We can use all versions greater than 1.0 |
|
We can use all versions lower than or equal to 2.0 |
|
We can use all versions lower than 2.0 |
In the following example build file, we will set the version for the spring-context module to greater than 4.0.1.RELEASE
and lower than 4.0.4.RELEASE
:
dependencies { // The dependency will resolve to version 4.0.3.RELEASE as // the latest version if available. Otherwise 4.0.2.RELEASE // or 4.0.1.RELEASE. compile 'org.springframework:spring-context:[4.0.1.RELEASE,4.0.4.RELEASE[' }