build: auto increment jar build names

This commit is contained in:
illyum 2025-04-09 13:23:41 -06:00
parent 91d881392e
commit 82c40c3047

View File

@ -1,4 +1,5 @@
import org.apache.commons.lang3.SystemUtils
import java.util.Properties
plugins {
idea
@ -9,25 +10,24 @@ plugins {
kotlin("jvm") version "2.0.0"
}
//Constants:
val baseGroup: String by project
val mcVersion: String by project
val version: String by project
val mixinGroup = "$baseGroup.mixin"
val versionBase: String by project
val buildNumber: String by project
val modid: String by project
val mixinGroup = "$baseGroup.mixin"
group = baseGroup
version = "$versionBase-b$buildNumber"
// Toolchains:
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}
// Minecraft configuration:
loom {
log4jConfigs.from(file("log4j2.xml"))
launchConfigs {
"client" {
// If you don't want mixins, remove these lines
property("mixin.debug", "true")
arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
}
@ -35,7 +35,6 @@ loom {
runConfigs {
"client" {
if (SystemUtils.IS_OS_MAC_OSX) {
// This argument causes a crash on macOS
vmArgs.remove("-XstartOnFirstThread")
}
}
@ -43,10 +42,8 @@ loom {
}
forge {
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
// If you don't want mixins, remove this lines
mixinConfig("mixins.$modid.json")
}
// If you don't want mixins, remove these lines
mixin {
defaultRefmapName.set("mixins.$modid.refmap.json")
}
@ -62,12 +59,9 @@ sourceSets.main {
kotlin.destinationDirectory.set(java.destinationDirectory)
}
// Dependencies:
repositories {
mavenCentral()
maven("https://repo.spongepowered.org/maven/")
// If you don't want to log in with your real minecraft account, remove this line
maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1")
}
@ -82,30 +76,24 @@ dependencies {
shadowImpl(kotlin("stdlib-jdk8"))
// If you don't want mixins, remove these lines
shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
isTransitive = false
}
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT")
// If you don't want to log in with your real minecraft account, remove this line
runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.2.1")
}
// Tasks:
tasks.withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
tasks.withType(org.gradle.jvm.tasks.Jar::class) {
archiveBaseName.set(modid)
archiveVersion.set("$version")
manifest.attributes.run {
this["FMLCorePluginContainsFMLMod"] = "true"
this["ForceLoadAsMod"] = "true"
// If you don't want mixins, remove these lines
this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker"
this["MixinConfigs"] = "mixins.$modid.json"
}
@ -124,7 +112,6 @@ tasks.processResources {
rename("(.+_at.cfg)", "META-INF/$1")
}
val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") {
archiveClassifier.set("")
from(tasks.shadowJar)
@ -145,12 +132,13 @@ tasks.shadowJar {
println("Copying dependencies into mod: ${it.files}")
}
}
// If you want to include other dependencies and shadow them, you can relocate them in here
fun relocate(name: String) = relocate(name, "$baseGroup.deps.$name")
}
tasks.assemble.get().dependsOn(tasks.remapJar)
tasks.assemble {
dependsOn(tasks.remapJar)
dependsOn("incrementBuildNumber")
}
tasks.register<Copy>("illyExtractMappings") {
from("O:/.gradle")
@ -160,7 +148,6 @@ tasks.register<Copy>("illyExtractMappings") {
tasks.register("illyApplyMappings") {
dependsOn("illyExtractMappings")
doLast {
// throw GradleException("${layout.buildDirectory.d}/mcp_mappings")
val mappingsDir = file("O:/Kotlin Programming/sbt/build/mcp_mappings")
if (mappingsDir.exists()) {
project.ext.set("mappingsPath", mappingsDir.absolutePath)
@ -175,4 +162,20 @@ tasks.withType<JavaCompile> {
doLast {
options.compilerArgs.add("-Amap=O:/Kotlin Programming/sbt/build/mcp_mappings")
}
}
}
// 🔁 Auto-increment build number each assemble
tasks.register("incrementBuildNumber") {
doLast {
val propsFile = file("gradle.properties")
val props = Properties()
props.load(propsFile.inputStream())
val current = props.getProperty("buildNumber")?.toIntOrNull() ?: 1
val next = current + 1
props.setProperty("buildNumber", next.toString())
props.store(propsFile.outputStream(), null)
println("🔢 Build number incremented to $next")
}
}