Skip to content

Instantly share code, notes, and snippets.

@emanuelet
Created April 15, 2015 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emanuelet/a377ee66a93976dcf4f1 to your computer and use it in GitHub Desktop.
Save emanuelet/a377ee66a93976dcf4f1 to your computer and use it in GitHub Desktop.
Gradle Versioning + Version Increment Task
[...]
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