Skip to content

Instantly share code, notes, and snippets.

@ralphpina
Created November 1, 2016 06:58
Show Gist options
  • Save ralphpina/b0917e39f0f80ad9abce1dc92017da8c to your computer and use it in GitHub Desktop.
Save ralphpina/b0917e39f0f80ad9abce1dc92017da8c to your computer and use it in GitHub Desktop.
task incrementVersion << {
def propsFile = file("../gradle.properties")
def propsText = propsFile.getText()
def patternVersionNumber = Pattern.compile("app_version=(\\d+)\\.(\\d+)\\.(\\d+)")
def matcherVersionNumber = patternVersionNumber.matcher(propsText)
matcherVersionNumber.find()
def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
def patchVersion = Integer.parseInt(matcherVersionNumber.group(3))
patchVersion++
if(patchVersion > 15) {
patchVersion = 0
minorVersion++
}
if(minorVersion > 10) {
minorVersion = 0
majorVersion++
}
propsText = matcherVersionNumber.replaceAll("app_version=" + majorVersion + "." + minorVersion + "." + patchVersion)
propsFile.write(propsText)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment