Reputation:
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?
Upvotes: 6
Views: 3671
Reputation: 3622
I've added this line on build.gradle.kts
version = System.getenv("NEW_VERSION") ?: "0.0.1-SNAPSHOT"
Not completely equivalent but works fine inside CI/CD scripts.
Upvotes: 0
Reputation: 6070
I successfully used Axion Release Plugin a couple of times and was very satisfied. Functionality-wise it comes the closest to what Maven's
Upvotes: 0
Reputation:
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.
Upvotes: 3
Reputation: 24498
Though not related to publishing, one way to pass command-line properties is as follows:
gradle -PWHATEVER_NEW_VERSION=2.0.0
Consider the following build.gradle
snippet:
def newVersion = project."WHATEVER_NEW_VERSION"
println newVersion
See ~/utils/gradle/version.gradle
in this project for another approach. It uses separate environment variables for major, minor, and incremental versions and then builds the string automatically. Because it resides in the gradle
directory, it can simply be imported into build.gradle
, which hides some boilerplate.
Upvotes: 3