Skip to content

Instantly share code, notes, and snippets.

@mitchwongho
Created May 15, 2015 08:36
Show Gist options
  • Save mitchwongho/7d20c72ea06fe6b304c0 to your computer and use it in GitHub Desktop.
Save mitchwongho/7d20c72ea06fe6b304c0 to your computer and use it in GitHub Desktop.
Automatic Android app versioning using git tags
def tags = "git -C ${rootDir} tag".execute().text.trim()
def numTags = tags.tokenize('\n').size()
// Fetch the version according to git latest tag and "how far are we from last tag"
def longVersionName = "git -C ${rootDir} describe --tags --long".execute().text.trim()
def (fullVersionTag, versionBuild, gitSha) = longVersionName.tokenize('-')
def(versionMajor, versionMinor, versionPatch) = fullVersionTag.tokenize('.')
// Set the version name
versionName "$versionMajor.$versionMinor.$versionPatch"
// Each tag is a new version code
versionCode numTags
// Friendly print the version output to the Gradle console
printf("\n--------" + "VERSION DATA--------" + "\n" + "- CODE: " + versionCode + "\n" +
"- NAME: " + versionName + "\n----------------------------\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment