Created
October 29, 2018 09:55
-
-
Save aerobless/8d6df5f26d4635622a1b544bca47af86 to your computer and use it in GitHub Desktop.
A way to easily increment major, minor or hotfix via gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def props = new Properties() | |
file("gradle.properties").withInputStream { props.load(it) } | |
int major | |
int minor | |
int hotfix | |
task readVersion() { | |
doFirst { | |
String version = props.getProperty("version") | |
println "Current Version: " + version | |
String[] versionParts = version.split('\\.') | |
major = Integer.parseInt(versionParts[0]) | |
minor = Integer.parseInt(versionParts[1]) | |
hotfix = Integer.parseInt(versionParts[2].split('-')[0]) | |
} | |
} | |
task incrementMajor() { | |
doFirst { | |
String version = ++major + "." + minor + "." + hotfix + "-SNAPSHOT" | |
props.setProperty("version", version) | |
file("gradle.properties").withOutputStream { p -> props.store(p, null) } | |
println "New Version: " + version | |
} | |
} | |
incrementMajor.dependsOn readVersion | |
task incrementMinor() { | |
doFirst { | |
String version = major + "." + ++minor + "." + hotfix + "-SNAPSHOT" | |
props.setProperty("version", version) | |
file("gradle.properties").withOutputStream { p -> props.store(p, null) } | |
println "New Version: " + version | |
} | |
} | |
incrementMinor.dependsOn readVersion | |
task incrementHotfix() { | |
doFirst { | |
String version = major + "." + minor + "." + ++hotfix + "-SNAPSHOT" | |
props.setProperty("version", version) | |
file("gradle.properties").withOutputStream { p -> props.store(p, null) } | |
println "New Version: " + version | |
} | |
} | |
incrementHotfix.dependsOn readVersion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment