diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 534aef5059..9d9844cf3b 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -1,3 +1,5 @@ +import org.gradle.api.Project + object BuildConfig { val MINECRAFT_VERSION: String = "1.21.1" val NEOFORGE_VERSION: String = "21.1.46" @@ -9,5 +11,31 @@ object BuildConfig { val PARCHMENT_VERSION: String? = null // https://semver.org/ - val MOD_VERSION: String = "0.6.0-beta.2" + var MOD_VERSION: String = "0.6.0-beta.2" + + fun createVersionString(project: Project): String { + val builder = StringBuilder() + + val isReleaseBuild = project.hasProperty("build.release") + val buildId = System.getenv("GITHUB_RUN_NUMBER") + + if (isReleaseBuild) { + builder.append(MOD_VERSION) + } else { + builder.append(MOD_VERSION.substringBefore('-')) + builder.append("-snapshot") + } + + builder.append("+mc").append(MINECRAFT_VERSION) + + if (!isReleaseBuild) { + if (buildId != null) { + builder.append("-build.${buildId}") + } else { + builder.append("-local") + } + } + + return builder.toString() + } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/multiloader-base.gradle.kts b/buildSrc/src/main/kotlin/multiloader-base.gradle.kts index faac526163..c23e78a4c6 100644 --- a/buildSrc/src/main/kotlin/multiloader-base.gradle.kts +++ b/buildSrc/src/main/kotlin/multiloader-base.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "net.caffeinemc" -version = BuildConfig.MOD_VERSION +version = BuildConfig.createVersionString(project) java.toolchain.languageVersion = JavaLanguageVersion.of(21) diff --git a/buildSrc/src/main/kotlin/multiloader-platform.gradle.kts b/buildSrc/src/main/kotlin/multiloader-platform.gradle.kts index 94da445d40..006f9f3500 100644 --- a/buildSrc/src/main/kotlin/multiloader-platform.gradle.kts +++ b/buildSrc/src/main/kotlin/multiloader-platform.gradle.kts @@ -13,10 +13,10 @@ dependencies { tasks { processResources { - inputs.property("version", BuildConfig.MOD_VERSION) + inputs.property("version", version) filesMatching(listOf("fabric.mod.json", "META-INF/neoforge.mods.toml")) { - expand(mapOf("version" to BuildConfig.MOD_VERSION)) + expand(mapOf("version" to version)) } } @@ -35,7 +35,7 @@ publishing { create("maven") { groupId = project.group as String artifactId = project.name as String - version = BuildConfig.MOD_VERSION + version = version from(components["java"]) }