A Gradle plugin that updates module and plugin versions in your *.gradle or *.gradle.kts files to the latest available versions.
This plugin depends on the Gradle Versions Plugin.
Maintainer: Patrik Erdes
Apply this plugin and the Gradle Versions Plugin.
Include in your build.gradle
plugins {
id 'se.patrikerdes.use-latest-versions' version '0.2.9'
id 'com.github.ben-manes.versions' version '0.21.0'
}
or
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
}
dependencies {
classpath "se.patrikerdes:gradle-use-latest-versions-plugin:0.2.9"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0'
}
}
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'se.patrikerdes.use-latest-versions'
Include in your build.gradle.kts
plugins {
id("se.patrikerdes.use-latest-versions") version "0.2.9"
id("com.github.ben-manes.versions") version "0.21.0"
}
or
buildscript {
repositories {
maven {
maven { url = uri("https://plugins.gradle.org/m2/") }
}
jcenter()
}
dependencies {
classpath("gradle.plugin.se.patrikerdes:gradle-use-latest-versions-plugin:0.2.9")
classpath("com.github.ben-manes:gradle-versions-plugin:0.21.0")
}
}
apply {
plugin("com.github.ben-manes.versions")
plugin("se.patrikerdes.use-latest-versions")
}
Given this build.gradle file:
plugins {
id 'se.patrikerdes.use-latest-versions' version '0.2.9'
id 'com.github.ben-manes.versions' version '0.19.0'
}
apply plugin: 'java'
repositories {
mavenCentral()
}
ext.log4jversion = '1.2.16'
ext.codecVersion = '1.9'
def commonsLoggingVersion = "1.1.2"
dependencies {
testCompile 'junit:junit:4.0'
compile "log4j:log4j:$log4jversion"
compile "commons-codec:commons-codec:" + codecVersion
compile group: 'commons-lang', name: 'commons-lang', version: '2.4'
compile group: 'commons-logging', name: 'commons-logging', version: commonsLoggingVersion
}
If you run
gradle useLatestVersions
Your plugin and module dependencies in build.gradle will be updated – both inline version number and versions based on variables – and you build.gradle file will look like this:
plugins {
id 'se.patrikerdes.use-latest-versions' version '0.2.9'
id 'com.github.ben-manes.versions' version '0.21.0' // <- Updated
}
apply plugin: 'java'
repositories {
mavenCentral()
}
ext.log4jversion = '1.2.17' // <- Updated
ext.codecVersion = '1.11' // <- Updated
def commonsLoggingVersion = "1.2" // <- Updated
dependencies {
testCompile 'junit:junit:4.12' // <- Updated
compile "log4j:log4j:$log4jversion" // <- The variable above was updated
compile "commons-codec:commons-codec:" + codecVersion // <- The variable above was updated
compile group: 'commons-lang', name: 'commons-lang', version: '2.6' // <- Updated
compile group: 'commons-logging', name: 'commons-logging', version: commonsLoggingVersion // <- The variable above was updated
}
# gradle useLatestVersions
Updates module and plugin versions in all *.gradle files in the project root folder or any subfolder to the latest
available versions. This task depends on the dependencyUpdates
task in the
Gradle Versions Plugin to know which dependencies can be updated.
# gradle useLatestVersions && gradle useLatestVersionsCheck
This task will succeed if all available updates were successfully applied by useLatestVersions
, and it will fail if
any of the updates were not successfully applied. This task depends on the dependencyUpdates
task in the
Gradle Versions Plugin to know which dependencies were
successfully updated.
useLatestVersionsCheck
can not run in the same gradle run as useLatestVersions
, since the dependencyUpdates
task
will check the *.gradle files as they were when the gradle build started, which means that it can not pick up the
changes applied by useLatestVersions
.
Dependencies stated in the following formats should cause the version to be successfully updated by the
useLatestVersions
task. (If not, please
create an issue.)
Single and double quotes are interchangeable in all formats below.
Plugin dependencies can only be updated in Gradle 4.4+.
The plugins DSL only allows a strict format, e.g. only string literals for the version number, so there is basically only one format to support.
plugins {
id 'se.patrikerdes.use-latest-versions' version '0.1.0'
}
dependencies {
compile "log4j:log4j:1.2.15"
testCompile 'junit:junit:4.0'
}
Currently only if the order is group
, name
, version
, without other elements in between.
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.0'
}
def
and ext.
(extra properties extensions) can be used interchangeably in all example below.
ext.junit_version = '4.0'
dependencies {
testCompile "junit:junit:$junit_version"
}
def junit_version = '4.0'
dependencies {
testCompile "junit:junit:${junit_version}"
}
ext.junit_version = '4.0'
dependencies {
testCompile "junit:junit:" + junit_version
}
Currently only if the order is group
, name
, version
, without other elements in between.
ext.junit_version = '4.0'
dependencies {
testCompile group: 'junit', name: 'junit', version: junit_version
}
Gradle version: 2.8 - 4.10.2 (Updating plugin dependencies only work in 4.4+)
Versions Plugin version: 0.12.0 - 0.21.0
JDK version: 7 - 11 (7 is targeted but not tested, 11 is currently not tested but is known to work)
- Clone or download this project.
- Open the project, for example in IntelliJ open the
build.gradle
file. - You can build the jar with the Gradle
assemble
task, it will be inbuild/libs/
. - If you want to use the plugin locally, first publish to your local Maven repository with the Gradle
publishToMavenLocal
task. - To use it in a different project, add to your
build.gradle
file
buildscript {
repositories {
mavenLocal()
}
dependencies{
classpath group: 'se.patrikerdes',
name: 'gradle-use-latest-versions-plugin',
version: '0.2.9'
}
}
apply plugin: se.patrikerdes.UseLatestVersionsPlugin
The Versions plugin can be configured to achieve this, it is documented in the Versions plugin README
From the Maven Versions Plugin goal called use-latest-versions
PR #23 Changes to address issues with Gradle multi-project builds. (b-behan)
Support com.github.ben-manes.versions version 0.21.0
PR #18, Support kt files within buildSrc. (Balthasar Biedermann)
Fixed issue #14, Kotlin dsl separate named and unnamed group name and version. (Balthasar Biedermann)
Fixed issue #15, changed the README to contain the correct way to use the plugin in a buildscript block.
Made the plugin work on Windows.
Fixed issue 10, Multiple versions in gradle.properties (Balthasar Biedermann)
PR #12, Support dependencySet of Spring Dependency management plugin. (Balthasar Biedermann)
PR #13, Support classifier and extension in dependencies. (Balthasar Biedermann)
Fixed issue 7, Update version variables in gradle.properties file, again. (0.2.4 didn't fix #7)
Fixed issue 8, Support for string interpolation with curly braces ${}
Fixed issue 7, Update version variables in gradle.properties file.
Fixed issue 3, Output formats are forced to be json,xml. (Tony Baines)
Fixed issue 2, Hardcoded Milestone Usage.
Added support for Gradle Kotlin DSL build files. (Thomas Schouten)