Skip to content

Instantly share code, notes, and snippets.

@dagezi
Created March 17, 2014 06:31
Show Gist options
  • Save dagezi/9594839 to your computer and use it in GitHub Desktop.
Save dagezi/9594839 to your computer and use it in GitHub Desktop.
Calculate SHA1 hash on gradle.
// file must be File object.
def calcSha1(file)
{
MessageDigest md = MessageDigest.getInstance("SHA-1");
file.eachByte 4096, {bytes, size ->
md.update(bytes, 0, size);
}
return md.digest().collect {String.format "%02x", it}.join();
}
@dnault
Copy link

dnault commented Nov 6, 2017

Thanks for the useful gist! With Groovy 1.8.6 and later, line 8 can be simplified to:

return md.digest().encodeHex()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment