Find latest Gradle version programatically

I’d like to run scheduled job to test my plugin against the latest Gradle version. What would be the best way to find one?

It would be great if something like ./gradlew wrapper --gradle-version=latest worked.

Any suggestions?

Thanks in advance.

You can create your own latestWrapper task to do this using the Gradle version web service. Splitting the configuration out into a separate task is a good idea so you don’t have every single build needing to hit the service. The distributionUrl for the Wrapper task is the downloadUrl in the JSON response.

ext.currentVersionService = 'https://services.gradle.org/versions/current'

task configureLatestWrapper {
    doLast {
        configure(tasks.'latestWrapper') {
            distributionUrl new groovy.json.JsonSlurper().parseText(new URL(currentVersionService).text).downloadUrl
        }
    }
}

task latestWrapper(type: Wrapper) {
    dependsOn configureLatestWrapper
    group = 'wrapper'
}
1 Like

Didn’t know about https://services.gradle.org/versions/current. Thanks @jjustinic!