Gradle - getting the latest release version of a dependency

风流意气都作罢 提交于 2019-11-26 19:34:17
Peter Niederwieser

Gradle currently does not support Maven's RELEASE (which is rarely used and deprecated) but it does support Ivy's latest.release. However, the general recommendation is to build against exact versions. Otherwise, the build can become a lottery.

It can be quite useful sometimes to get the latest release - if for example you release often your own dependencies.

You can get the latest version like

compile "junit:junit:+"

or better specify at least the major version like

compile "junit:junit:4.+"

Check out the Gradle-Versions-Plugin. It does exactly what you want: https://github.com/ben-manes/gradle-versions-plugin

For the installation, see the github page. Basically you need to add these two lines to your build.gradle - project file:

apply plugin: 'com.github.ben-manes.versions'

buildscript {
    [...]
    dependencies {
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.8'
        [...]
    }
}
[...]

Then you can use the plugin, by running this command in terminal in your project dir:

./gradlew dependencyUpdates -Drevision=release

And it will show you which dependencies are outdated!

Latest Gradle User Guide mentions and explains plus sign in versions:

From 7.2. Declaring your dependencies:

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

... The build script also states that any junit >= 4.0 is required to compile the project's tests.

From 23.7. How dependency resolution works:

If the dependency is declared as a dynamic version (like 1.+), Gradle will resolve this to the newest available static version (like 1.2) in the repository. For Maven repositories, this is done using the maven-metadata.xml file, while for Ivy repositories this is done by directory listing.

In Android Studio:

If you're using + for the version, and want to know which version is actually being used, select Project in the sidebar, and then under External Libraries you will see the actual version number in use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!