Created
November 1, 2016 06:58
-
-
Save ralphpina/b0917e39f0f80ad9abce1dc92017da8c 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
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