From 6870c37b942ae7903220822624eba8dbe4a1f037 Mon Sep 17 00:00:00 2001 From: off-by-0point5 <61155885+off-by-0point5@users.noreply.github.com> Date: Sat, 31 Dec 2022 04:09:07 +0100 Subject: [PATCH] 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 --- build.gradle.kts | 17 +++++++++++++++++ gradle/libs.versions.toml | 7 +++++++ src/main/java/net/minestom/server/Git.java | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/net/minestom/server/Git.java diff --git a/build.gradle.kts b/build.gradle.kts index 5c8299fcc..32f8a0377 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { `java-library` id("minestom.publishing-conventions") id("minestom.native-conventions") + alias(libs.plugins.blossom) } allprojects { @@ -39,6 +40,21 @@ tasks { withType { 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 { @@ -80,3 +96,4 @@ dependencies { api("io.github.jglrxavpok.hephaistos:common:${libs.versions.hephaistos.get()}") api("io.github.jglrxavpok.hephaistos:gson:${libs.versions.hephaistos.get()}") } + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6f7cf0b17..2d34cb966 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,6 +39,9 @@ jmh = "1.35" # JCStress jcstress = "0.8" +# Gradle plugins +blossom = "1.3.0" + [libraries] # 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"] logging = ["tinylog-api", "tinylog-impl", "tinylog-slf4j"] terminal = ["jline", "jline-jansi"] + +[plugins] + +blossom = { id = "net.kyori.blossom", version.ref = "blossom" } diff --git a/src/main/java/net/minestom/server/Git.java b/src/main/java/net/minestom/server/Git.java new file mode 100644 index 000000000..445eb6468 --- /dev/null +++ b/src/main/java/net/minestom/server/Git.java @@ -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; } +}