Skip to content

Instantly share code, notes, and snippets.

@scf37
Created January 9, 2022 12:45
Show Gist options
  • Save scf37/c4ab3e3e2358f2255a70cc45f7f996f6 to your computer and use it in GitHub Desktop.
Save scf37/c4ab3e3e2358f2255a70cc45f7f996f6 to your computer and use it in GitHub Desktop.
build-info gradle plugin, adding everything to manifest
import java.io.ByteArrayOutputStream
import java.time.ZonedDateTime
fun exec(vararg args: String) = try {
ByteArrayOutputStream().also { os ->
project.exec {
commandLine(*args)
standardOutput = os
}
}.toByteArray().let { String(it) }.trim()
.replace("\\", "\\\\")
.replace("\r", "")
.replace("\n", "\\n")
} catch (e: Exception) {
"NONE"
}
tasks.withType(Jar::class) {
manifest {
attributes["Manifest-Version"] = "1.0"
attributes["Implementation-Title"] = project.name
attributes["Implementation-Version"] = project.version
attributes["Build-Timestamp"] = ZonedDateTime.now().toString()
attributes["Build-Revision"] = exec("git", "rev-parse", "HEAD")
attributes["Build-Scm-Repository"] = exec("git", "config", "--get", "remote.origin.url")
attributes["Build-Last-Few-Commits"] = exec("git", "log", "-n", "5", "--pretty=%h %ad %an %s")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment