原贴:https://discuss.mc9y.com/d/22在使用 Kotlin 开发 Forge 模组时,使用 shadow 构建无法正确替换映射表的时候,这是一个解决方案示例。
代码:
import net.minecraftforge.gradle.userdev.UserDevExtension
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
buildscript {
repositories {
maven("https://files.minecraftforge.net/maven")
}
dependencies {
classpath("net.minecraftforge.gradle:ForgeGradle:3.+")
}
}
plugins {
kotlin("jvm") version "1.9.21"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.minecraftforge.gradle") version "[6.0.16,6.2)"
}
dependencies {
minecraft("net.minecraftforge:forge:1.12.2-14.23.5.2860")
}
val Project.configureMinecraft get() = extensions.getByName<UserDevExtension>("minecraft")
configureMinecraft.mappings("snapshot", "20171003-1.12")
kotlin {
jvmToolchain(8)
}
tasks {
shadowJar {
relocate("kotlin", "com.aiyostudio.kotlin")
dependencies {
include(dependency("org.jetbrains.kotlin:kotlin-stdlib:1.9.21"))
}
}
}
tasks.jar {
finalizedBy("reobfJar")
}
val reobfJar: TaskProvider<RenameJarInPlace> = tasks.register("reobfJar", RenameJarInPlace::class)
reobfJar.configure {
dependsOn(tasks.shadowJar)
}
fun DependencyHandler.minecraft(
dependencyNotation: Any
): Dependency? = add("minecraft", dependencyNotation)