Skip to content

Instantly share code, notes, and snippets.

@timkrins
Created April 26, 2017 15:27
Show Gist options
  • Save timkrins/366d42fcf39a4341678438dedb33896f to your computer and use it in GitHub Desktop.
Save timkrins/366d42fcf39a4341678438dedb33896f to your computer and use it in GitHub Desktop.
Generate Google Maps hash at end of Gradle build
import java.util.regex.Pattern
def getGoogleMapsHash = { ->
def pattern = Pattern.compile("SHA1: ([0-9a-fA-F:]+)")
try {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine "keytool", "-list", "-v", "-keystore", file(STORE_FILE), "-storepass", STORE_PASSWORD
standardOutput = stdOut
}
def hashString = stdOut.toString().trim()
def matcher = pattern.matcher(hashString)
matcher.find()
return matcher.group(1)
}
catch (error) {
return error.toString();
}
}
gradle.buildFinished {
println "Google Maps Hash:\n " + getGoogleMapsHash() + "\n"
}
STORE_FILE=C:/Keystore.jks
STORE_PASSWORD=password
KEY_ALIAS=keystoreAlias
KEY_PASSWORD=password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment