Skip to content

Commit

Permalink
[LI-HOTFIX] embed versioning information in jars (v2) (#47)
Browse files Browse the repository at this point in the history
TICKET = LIKAFKA-25730
LI_DESCRIPTION = embed version info into library jars to be able to query at runtime

EXIT_CRITERIA = never

Signed-off-by: Radai Rosenblatt <[email protected]>
  • Loading branch information
radai-rosenblatt authored Sep 10, 2019
1 parent 12e7805 commit 6a3776a
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,34 @@ subprojects {
//
//this information allows us, at runtime, to determine what libraries/versions exist on a given classpath

MessageDigest md = MessageDigest.getInstance("MD5")
md.update(String.valueOf(project.group).getBytes("UTF-8"))
md.update(String.valueOf(project.name).getBytes("UTF-8"))
md.update(String.valueOf(project.version).getBytes("UTF-8"))
byte[] digest = md.digest()
String hash = DatatypeConverter.printHexBinary(digest).toUpperCase()

String versioningFileName = "__Versioning__" + hash
String versioningPayload = "{" +
"\"format\":\"v1\"," +
"\"project\":\"" + rootProject.group + ":" + rootProject.name + ":" + rootProject.version + "\"," +
"\"module\":\"" + project.group + ":" + project.name + ":" + project.version + "\"" +
"}"

String outFolder = "${project.buildDir}/resources/main/META-INF/"
mkdir outFolder
file("${outFolder}/${versioningFileName}").text = versioningPayload
String moduleVersion = String.valueOf(project.version)
String projectVersion = String.valueOf(rootProject.version)

if ("unspecified" != projectVersion && "unspecified" != moduleVersion) {
MessageDigest md = MessageDigest.getInstance("MD5")
md.update(String.valueOf(project.group).getBytes("UTF-8"))
md.update(String.valueOf(project.name).getBytes("UTF-8"))
md.update(moduleVersion.getBytes("UTF-8"))
byte[] digest = md.digest()
String hash = DatatypeConverter.printHexBinary(digest).toUpperCase()

String versioningFileName = "__Versioning__" + hash
String versioningPayload = "{" +
"\"format\":\"v1\"," +
"\"project\":\"" + rootProject.group + ":" + rootProject.name + ":" + projectVersion + "\"," +
"\"module\":\"" + project.group + ":" + project.name + ":" + moduleVersion + "\"" +
"}"

String outFolder = "${project.buildDir}/resources/main/META-INF/"
mkdir outFolder

fileTree(dir: outFolder, include:'__Versioning__*').each {
//remove any left-overs from previous builds
it.delete()
}

file("${outFolder}/${versioningFileName}").text = versioningPayload
}
}

from "$rootDir/LICENSE"
Expand Down

0 comments on commit 6a3776a

Please sign in to comment.