Created
February 18, 2015 04:19
-
-
Save creativepsyco/442cb06216d93a313c58 to your computer and use it in GitHub Desktop.
Automatically add Git revision information when building SNAPSHOT versions of an App
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
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