Created
April 15, 2015 05:33
-
-
Save emanuelet/a377ee66a93976dcf4f1 to your computer and use it in GitHub Desktop.
Gradle Versioning + Version Increment Task
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 vFile = new File( 'version.properties' ) | |
Properties props = new Properties() | |
props.load( new FileInputStream( vFile ) ) | |
def versionMajor = props.get( 'versionMajor' ).toInteger() | |
def versionMinor = props.get( 'versionMinor' ).toInteger() | |
def versionPatch = props.get( 'versionPatch' ).toInteger() | |
[...] | |
defaultConfig { | |
... | |
versionCode versionMajor * 1000 + versionMinor * 100 + versionPatch * 10 | |
versionName "${versionMajor}.${versionMinor}.${versionPatch}" | |
... | |
} | |
[...] | |
//====================================================================== | |
// Takes the version variables and increments them exponentially | |
//====================================================================== | |
task incrementVersion << { | |
println(":incrementVersion - Incrementing Version...") | |
props.load( new FileInputStream( vFile ) ) | |
Integer vMajor = props.get( 'versionMajor' ).toInteger() | |
Integer vMinor = props.get( 'versionMinor' ).toInteger() | |
Integer vPatch = props.get( 'versionPatch' ).toInteger() | |
// Integer vBuild = props.get( 'versionBuild' ).toInteger() | |
vPatch=vPatch+1 | |
if (vPatch==10) { | |
vPatch=0 | |
vMinor=vMinor+1 | |
if (vMinor==10) { | |
vMinor=0 | |
vMajor=vMajor+1 | |
} | |
} | |
props.setProperty('versionMajor', vMajor.toString()) | |
props.setProperty('versionMinor', vMinor.toString()) | |
props.setProperty('versionPatch', vPatch.toString()) | |
props.store(vFile.newWriter(), null) | |
println("New Version: "+vMajor +"."+ vMinor +"."+ vPatch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment