Skip to content

Instantly share code, notes, and snippets.

@sddamico
Created October 20, 2014 20:25
Show Gist options
  • Save sddamico/147bee247374b8bb7a33 to your computer and use it in GitHub Desktop.
Save sddamico/147bee247374b8bb7a33 to your computer and use it in GitHub Desktop.
Groovy increment versionCode in gradle.properties
// increment the versionCode in the build.properties file
def incrementBuildPropertiesVersion() {
// load build.properties file
def buildProps = new Properties()
def buildPropsFile = new File('android/build.properties')
buildProps.load(buildPropsFile.newDataInputStream())
// get old version code from properties file
def oldVersionCode = buildProps.getProperty('VERSION_CODE')
def newVersionCode = Integer.parseInt(oldVersionCode) + 1
println "Incrementing versionCode from ${oldVersionCode} to ${newVersionCode}"
buildProps.setProperty('VERSION_CODE', "${newVersionCode}")
// write properties file back to system
println "Writing build.properties"
buildProps.store(buildPropsFile.newWriter(), null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment