Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gradle: how to get git hash in build.gradle
String getGitHash() {
// git hash
def command = Runtime.getRuntime().exec("git rev-parse --short HEAD")
def result = command.waitFor()
if (result != 0) {
throw new IOException("Command 'getGitHash()' exited with " + result)
String gitCommitHash = command.inputStream.text.trim()
//println("getGitHash() : " + gitCommitHash)
return gitCommitHash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment