Created
June 16, 2020 17:54
-
-
Save josiahhaswell/fd18bf9b0857c0927d367be972408ebc to your computer and use it in GitHub Desktop.
This file contains 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 loadProperties() { | |
def props = new Properties() | |
def file = new File("gradle.properties") | |
file.withInputStream { | |
props.load(it) | |
} | |
return props | |
} | |
def writeProperties(props) { | |
props.store(new File("gradle.properties").newWriter(), null) | |
} | |
def setVersion() { | |
def newVersion = System.getProperty("newVersion") | |
if(!newVersion) { | |
newVersion = "${System.getenv("CURRENT_MAJOR_VERSION")}.${System.getenv("CURRENT_MINOR_VERSION")}.${System.getenv("BUILD_NUMBER")}" | |
if(System.getProperty("zephyrRelease")) { | |
newVersion += ".Final" | |
} else { | |
newVersion += "-SNAPSHOT" | |
} | |
} | |
if(newVersion) { | |
println("Setting version from ${project.version} to $newVersion") | |
def props = loadProperties() | |
props.version = newVersion.toString() | |
writeProperties(props) | |
println("successfully updated project version ${project.version} to $newVersion") | |
} else { | |
logger.warn("No new version passed in. Not doing anything") | |
} | |
} | |
project.tasks.register("setVersion") { | |
doLast { | |
setVersion() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment