Search code examples
mavengradlebuild.gradlegradle-pluginmaven-versions-plugin

Gradle equivalent of maven-versions-plugin


This is my build.gradle:

group 'whatever'
version '1.0.0-SNAPSHOT'

...

dependencies {
    compile 'whatever:2.2.1-SNAPSHOT'
}

I want to automate releasing process, which includes the need to set both versions to particular values, e.g. 1.1.0 or 2.2.0 using command line only. Any kind of autoincrement is not an option.

With Maven, I'd do this using maven-versions-plugin:

mvn versions:set -DnewVersion=${WHATEVER_NEW_VERSION}

How can I do the same with Gradle? I only found this unanswered question. There must be some simple way to do that?


Solution

  • I ended up extracting version numbers to gradle.properties and updating them as part of the automated build script using sed:

    sed -i -e \"/someVersionNumber=/ s/=.*/=${SOME_NEW_VERSION_NUMBER}/\" gradle.properties
    

    It's what I want. Although for me, coming from the Maven background, this doesn't seem natural. I may research another alternative later.