Skip to content

Commit

Permalink
Restore versioning schema to build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Oct 26, 2024
1 parent dc7dc4c commit b3c70d5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
30 changes: 29 additions & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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()
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/multiloader-base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "net.caffeinemc"
version = BuildConfig.MOD_VERSION
version = BuildConfig.createVersionString(project)

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/multiloader-platform.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand All @@ -35,7 +35,7 @@ publishing {
create<MavenPublication>("maven") {
groupId = project.group as String
artifactId = project.name as String
version = BuildConfig.MOD_VERSION
version = version

from(components["java"])
}
Expand Down

0 comments on commit b3c70d5

Please sign in to comment.