Created
January 9, 2022 12:45
-
-
Save scf37/c4ab3e3e2358f2255a70cc45f7f996f6 to your computer and use it in GitHub Desktop.
build-info gradle plugin, adding everything to manifest
This file contains 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
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