-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Description
I'm using the ReplayMod preprocessor to manage multi-version Minecraft mod development. My goal is to inject different build.gradle.kts scripts for subprojects directly in settings.gradle.kts, but the current implementation of createNode and link methods are only available in the project evaluation phase (e.g., build.gradle.kts). This forces me to redefine version/subproject mappings twice (once in preprocess config, once in settings.gradle.kts), which is redundant and error-prone—especially since createNode already contains subproject names (folder paths) that I need for settings configuration.
Current preprocess Configuration (in build.gradle.kts)
preprocess {
strictExtraMappings = false
// val mc1_18_02 = createNode("1.18.2", 1_18_02, "")
val mc1_19_00 = createNode("1.19", 1_19_00, "")
val mc1_19_01 = createNode("1.19.1", 1_19_01, "")
// ... (omitted repetitive node definitions for brevity)
val mc1_21_07 = createNode("1.21.7", 1_21_07, "")
val mc1_21_08 = createNode("1.21.8", 1_21_08, "")
val mc1_21_09 = createNode("1.21.9", 1_21_09, "")
val mc1_21_10 = createNode("1.21.10", 1_21_10, "")
val mc1_21_11 = createNode("1.21.11", 1_21_11, "")
val mc26_00_01 = createNode("26.1", 26_00_01, "")
mc26_00_01.link(mc1_21_11, file("versions/mapping-1.21.11-26.1.txt"))
mc1_21_11.link(mc1_21_10, file("versions/mapping-1.21.10-1.21.11.txt"))
mc1_21_10.link(mc1_21_09, null)
mc1_21_09.link(mc1_21_08, null)
// ... (omitted repetitive link calls for brevity)
mc1_19_04.link(mc1_19_03, null)
mc1_19_03.link(mc1_19_02, file("versions/mapping-1.19.2-1.19.3.txt"))
mc1_19_02.link(mc1_19_01, null)
mc1_19_01.link(mc1_19_00, null)
// mc1_18_02.link(mc1_18_01, null)
// See https://github.com/Fallen-Breath/fabric-mod-template/blob/1d72d77a1c5ce0bf060c2501270298a12adab679/build.gradle#L55-L63
for (node in getNodes()) {
findProject(node.project)
?.ext
?.set("mcVersion", node.mcVersion)
}
}My Current Workaround (Redundant Definition in settings.gradle.kts)
To achieve build script injection, I have to re-parse version info and redefine subproject mappings manually (duplicating logic from preprocess):
@Suppress("UNCHECKED_CAST")
val settings = JsonSlurper().parseText(file("settings.json").readText()) as Map<String, List<String>>
for (version in settings["versions"]!!) {
include(":$version")
project(":$version").apply {
projectDir = file("versions/$version")
buildFileName = if (parseMcVersionToNumber(version) > 260000) {
"../../build.fabric.gradle.kts"
} else {
"../../build.fabric.remap.gradle.kts"
}
}
}
fun parseMcVersionToNumber(mcVersionStr: String): Int {
val cleanVersion = mcVersionStr.split("-")[0] // Remove suffixes like -fabric/-pre/-rc
.replace(Regex("[^0-9.]"), "") // Remove non-numeric/non-dot characters
val versionParts = cleanVersion.split(".")
.filter { it.isNotEmpty() } // Filter empty strings (avoid abnormal splitting)
val major = versionParts.getOrNull(0)?.toIntOrNull() ?: 0
val minor = versionParts.getOrNull(1)?.toIntOrNull() ?: 0
val patch = versionParts.getOrNull(2)?.toIntOrNull() ?: 0
return major * 10000 + minor * 100 + patch
}Expected Implementation (Ideal settings.gradle.kts)
If createNode/link and the preprocess extension were available in settings.gradle.kts, I could avoid duplication and use the pre-defined node data directly:
preprocess {
strictExtraMappings = false
// val mc1_18_02 = createNode("1.18.2", 1_18_02, "")
val mc1_19_00 = createNode("1.19", 1_19_00, "")
// ... (omitted repetitive node definitions for brevity)
val mc1_21_10 = createNode("1.21.10", 1_21_10, "")
val mc1_21_11 = createNode("1.21.11", 1_21_11, "")
val mc26_00_01 = createNode("26.1", 26_00_01, "")
mc26_00_01.link(mc1_21_11, file("versions/mapping-1.21.11-26.1.txt"))
mc1_21_11.link(mc1_21_10, file("versions/mapping-1.21.10-1.21.11.txt"))
// ... (omitted repetitive link calls for brevity)
mc1_19_02.link(mc1_19_01, null)
mc1_19_01.link(mc1_19_00, null)
// Use preprocess nodes directly for subproject configuration
for (node in getNodes()) {
include(":${node.project}")
project(":${node.project}").apply {
projectDir = file("versions/${node.project}")
buildFileName = if (node.mcVersion > 260000) {
"../../build.fabric.gradle.kts"
} else {
"../../build.fabric.remap.gradle.kts"
}
ext.set("version", node.mcVersion)
}
}
}
Feature Request
-
Make createNode and link methods accessible in the settings.gradle.kts phase (Gradle settings scope), not just in project evaluation.
-
Globalize the preprocess extension so its configuration (nodes/mappings) can be reused across settings.gradle.kts and build.gradle.kts, eliminating redundant version/subproject definitions.
This change would streamline multi-version mod development by centralizing version/subproject configuration in the preprocess extension and making it usable throughout the Gradle build lifecycle.
Thank you for considering this request!