Last active
January 28, 2019 07:46
-
-
Save pgilad/204e6d93b3ca3382bed6f7922eef073f to your computer and use it in GitHub Desktop.
Create a revision for file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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