Skip to content

Instantly share code, notes, and snippets.

@pgilad pgilad/build.gradle.kts
Last active Jan 28, 2019

Embed
What would you like to do?
Create a revision for file
fun digest(file: File, algorithm: String): String {
val contents = file.readBytes()
val messageDigest = MessageDigest.getInstance(algorithm)
val digestBytes = messageDigest.digest(contents)
return String.format("%032x", BigInteger(1, digestBytes)).substring(0..9)
}
project(":jetpack").configure {
apply(plugin = "com.github.johnrengelman.shadow")
tasks.register("rev") {
group = "build"
description = "Append revision to output jar"
val shadowJar by tasks.getting(ShadowJar::class)
dependsOn(shadowJar)
inputs.files(shadowJar)
outputs.dir(shadowJar.destinationDir)
doLast {
copy {
val singleFile = shadowJar.outputs.files.singleFile
val hash = digest(file(singleFile), "SHA-256")
from(singleFile)
into(shadowJar.destinationDir)
include("*-all.jar")
rename("(.+)-all.jar", "$1-$hash-all.jar")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.