Add commit info from JitPack into Minestom's jar (#1272)

* Compile git info into Git.java

* Move blossom task into tasks block

* Fix javadoc task

* Improve readability

* Remove version field

* Hopefully preventing inline by javac

* Make Git class final

* Remove prefixes for getters

* Make getters static
This commit is contained in:
off-by-0point5 2022-12-31 04:09:07 +01:00 committed by GitHub
parent 9890d71347
commit 6870c37b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -2,6 +2,7 @@ plugins {
`java-library` `java-library`
id("minestom.publishing-conventions") id("minestom.publishing-conventions")
id("minestom.native-conventions") id("minestom.native-conventions")
alias(libs.plugins.blossom)
} }
allprojects { allprojects {
@ -39,6 +40,21 @@ tasks {
withType<Zip> { withType<Zip> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE duplicatesStrategy = DuplicatesStrategy.EXCLUDE
} }
blossom {
val git = "src/main/java/net/minestom/server/Git.java"
val gitCommit = System.getenv("GIT_COMMIT")
val gitBranch = System.getenv("GIT_BRANCH")
val group = System.getenv("GROUP")
val artifact = System.getenv("ARTIFACT")
replaceToken("\"&COMMIT\"", if (gitCommit == null) "null" else "\"${gitCommit}\"", git)
replaceToken("\"&BRANCH\"", if (gitBranch == null) "null" else "\"${gitBranch}\"", git)
replaceToken("\"&GROUP\"", if (group == null) "null" else "\"${group}\"", git)
replaceToken("\"&ARTIFACT\"", if (artifact == null) "null" else "\"${artifact}\"", git)
}
} }
dependencies { dependencies {
@ -80,3 +96,4 @@ dependencies {
api("io.github.jglrxavpok.hephaistos:common:${libs.versions.hephaistos.get()}") api("io.github.jglrxavpok.hephaistos:common:${libs.versions.hephaistos.get()}")
api("io.github.jglrxavpok.hephaistos:gson:${libs.versions.hephaistos.get()}") api("io.github.jglrxavpok.hephaistos:gson:${libs.versions.hephaistos.get()}")
} }

View File

@ -39,6 +39,9 @@ jmh = "1.35"
# JCStress # JCStress
jcstress = "0.8" jcstress = "0.8"
# Gradle plugins
blossom = "1.3.0"
[libraries] [libraries]
# Important Dependencies # Important Dependencies
@ -104,3 +107,7 @@ flare = ["flare", "flare-fastutil"]
adventure = ["adventure-api", "adventure-serializer-gson", "adventure-serializer-legacy", "adventure-serializer-plain", "adventure-text-logger-slf4j"] adventure = ["adventure-api", "adventure-serializer-gson", "adventure-serializer-legacy", "adventure-serializer-plain", "adventure-text-logger-slf4j"]
logging = ["tinylog-api", "tinylog-impl", "tinylog-slf4j"] logging = ["tinylog-api", "tinylog-impl", "tinylog-slf4j"]
terminal = ["jline", "jline-jansi"] terminal = ["jline", "jline-jansi"]
[plugins]
blossom = { id = "net.kyori.blossom", version.ref = "blossom" }

View File

@ -0,0 +1,16 @@
package net.minestom.server;
public final class Git {
private static final String COMMIT = "&COMMIT";
private static final String BRANCH = "&BRANCH";
private static final String GROUP = "&GROUP";
private static final String ARTIFACT = "&ARTIFACT";
public static String commit() { return COMMIT; }
public static String branch() { return BRANCH; }
public static String group() { return GROUP; }
public static String artifact() { return ARTIFACT; }
}