Skip to content

Instantly share code, notes, and snippets.

@creativepsyco
Created February 18, 2015 04:19
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 creativepsyco/442cb06216d93a313c58 to your computer and use it in GitHub Desktop.
Save creativepsyco/442cb06216d93a313c58 to your computer and use it in GitHub Desktop.
Automatically add Git revision information when building SNAPSHOT versions of an App
Integer VERSION_CODE = 16
String VERSION_NAME = getVersionName("0.4-SNAPSHOT")
def getVersionName(String preferredVersionName) {
if (preferredVersionName.contains("-SNAPSHOT")) {
return getGitStatus(preferredVersionName)
} else {
return preferredVersionName
}
}
def getGitStatus(String versionName) {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe'
standardOutput = stdout
}
return versionName + '-' + stdout.toString().trim()
}
catch (ignored) {
return versionName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment