Skip to content

Instantly share code, notes, and snippets.

@pratul
Last active March 1, 2017 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pratul/dc09131331049e7c4917b8df1ff67af0 to your computer and use it in GitHub Desktop.
Save pratul/dc09131331049e7c4917b8df1ff67af0 to your computer and use it in GitHub Desktop.
A gradle method to generate Android versionCode using git describe.
def getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--first-parent', '--count', 'origin/master'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim()) * 100
}
catch (ignored) {
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment