From 21db565efdd32decbad1d92bad08e89b8e044cb0 Mon Sep 17 00:00:00 2001 From: makamys Date: Tue, 7 Feb 2023 15:02:03 +0100 Subject: [PATCH] Merge GTNHMix's build logic --- module-mixin/build.gradle | 122 +++++++++++--------------------------- 1 file changed, 33 insertions(+), 89 deletions(-) diff --git a/module-mixin/build.gradle b/module-mixin/build.gradle index d46abcd..631848c 100644 --- a/module-mixin/build.gradle +++ b/module-mixin/build.gradle @@ -41,8 +41,8 @@ apply plugin: "com.github.johnrengelman.shadow" configurations.create("shadow$_flavor") configurations.create("shadowBridge$_flavor") - if (mixinFlavor == "fabric" || mixinFlavor == "spongepowered" || mixinFlavor == "unimix") { - // Fabric / SpongePowered / UniMix + if (mixinFlavor == "fabric" || mixinFlavor == "spongepowered" || mixinFlavor == "unimix" || mixinFlavor == "gtnh") { + // Fabric / SpongePowered / UniMix / GTNH if (mixinFlavor == "fabric" || mixinFlavor == "unimix") { def mixinVersion = mixinFlavor == "fabric" ? "0.11.4+mixin.0.8.5" : "0.11.5+mixin.0.8.5" @@ -65,7 +65,7 @@ apply plugin: "com.github.johnrengelman.shadow" transitive = false }) } - } else { + } else if(mixinFlavor == "spongepowered") { mixinFlavorClassifier = "spongepowered-0.8.5" dependencies { @@ -79,6 +79,22 @@ apply plugin: "com.github.johnrengelman.shadow" add("shadow$_flavor", 'org.ow2.asm:asm-commons:9.2') add("shadow$_flavor", 'org.ow2.asm:asm-util:9.2') } + } else if(mixinFlavor == "gtnh") { + // Adapted from GTNHMixins's build script + + def mixinVersion = "0.8.5-GTNH-2" + mixinFlavorClassifier = "gtnh-$mixinVersion" + def asmVersion = "9.4" + + dependencies { + add("shadow$_flavor", "org.spongepowered:mixin:$mixinVersion") + add("shadow$_flavor", "org.ow2.asm:asm-tree:$asmVersion") + add("shadow$_flavor", "org.ow2.asm:asm-commons:$asmVersion") + add("shadow$_flavor", "org.ow2.asm:asm-util:$asmVersion") + add("shadow$_flavor", "com.google.guava:guava:21.0") + add("shadowBridge$_flavor", 'org.spongepowered:mixin:0.8.5') + } + } // We want to *not* relocate ASM in the bridge classes. So we use a multi-step @@ -90,8 +106,15 @@ apply plugin: "com.github.johnrengelman.shadow" classifier = "tmpMixin$_flavor" configurations = [project.configurations."shadow$_flavor"] - relocate 'com.google', 'org.spongepowered.libraries.com.google' relocate 'org.objectweb.asm', 'org.spongepowered.asm.lib' + if(mixinFlavor != "gtnh") { + relocate 'com.google', 'org.spongepowered.libraries.com.google' + } else { + // we don't use this ASM package name + //relocate 'org.objectweb.asm', 'org.spongepowered.libraries.org.objectweb.asm' + relocate 'com.google.common', 'org.spongepowered.libraries.com.google.common' + relocate 'com.google.thirdparty.publicsuffix', 'org.spongepowered.libraries.com.google.thirdparty.publicsuffix' + } exclude 'org/spongepowered/asm/bridge/RemapperAdapter.class' exclude 'org/spongepowered/asm/bridge/RemapperAdapterFML.class' @@ -106,10 +129,12 @@ apply plugin: "com.github.johnrengelman.shadow" exclude 'META-INF/services/cpw.mods.modlauncher.api.ITransformationService' exclude 'META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService' + + exclude '**/module-info.class' // Exclude jar-specific stuff - exclude 'META-INF/MUMFREY*' + exclude 'META-INF/MANIFEST.MF', 'META-INF/maven/**', 'META-INF/*.RSA', 'META-INF/*.SF' } // 2. Create Mixin jar without relocation, with *only* the bridge classes @@ -129,7 +154,8 @@ apply plugin: "com.github.johnrengelman.shadow" exclude "mcmod.info" } - //enabled = false + dependsOn "mixinJar$_flavor" + dependsOn "bridgeJar$_flavor" dependsOn "mixinJar$_flavor" dependsOn "bridgeJar$_flavor" @@ -138,7 +164,7 @@ apply plugin: "com.github.johnrengelman.shadow" doLast { delete tasks."mixinJar$_flavor".archiveFile - delete tasks."bridgeJar$_flavor" + delete tasks."bridgeJar$_flavor".archiveFile } manifest { @@ -178,88 +204,6 @@ apply plugin: "com.github.johnrengelman.shadow" } } - jar.dependsOn("shadowJar$_flavor") - } else if (mixinFlavor == "gtnh") { - // GTNH - - // Adapted from GTNHMixins's build script - - def mixinVersion = "0.8.5-GTNH-2" - mixinFlavorClassifier = "gtnh-$mixinVersion" - def asmVersion = "9.4" - - dependencies { - add("shadow$_flavor", "org.spongepowered:mixin:$mixinVersion") - add("shadow$_flavor", "org.ow2.asm:asm-tree:$asmVersion") - add("shadow$_flavor", "org.ow2.asm:asm-commons:$asmVersion") - add("shadow$_flavor", "org.ow2.asm:asm-util:$asmVersion") - add("shadow$_flavor", "com.google.guava:guava:21.0") - add("shadowBridge$_flavor", 'org.spongepowered:mixin:0.8.5') - } - - // We want to *not* relocate ASM in the bridge classes. So we use a multi-step - // build procedure: - - // 1. Create relocated Mixin jar, without the bridge classes - task("mixinJar$_flavor", type: ShadowJar) { - destinationDirectory = file("build/tmp") - archiveFileName.set("mixin-$mixinVersion-repack.jar") - configurations = [project.configurations."shadow$_flavor"] - - mergeServiceFiles() - - exclude 'META-INF/MANIFEST.MF', 'META-INF/maven/**', 'META-INF/*.RSA', 'META-INF/*.SF' - exclude '**/module-info.class' - - // we use this instead of 'org.spongepowered.libraries.org.objectweb.asm' - relocate 'org.objectweb.asm', 'org.spongepowered.asm.lib' - relocate 'com.google.common', 'org.spongepowered.libraries.com.google.common' - relocate 'com.google.thirdparty.publicsuffix', 'org.spongepowered.libraries.com.google.thirdparty.publicsuffix' - } - - // 2. Create Mixin jar without relocation, with *only* the bridge classes - task("bridgeJar$_flavor", type: ShadowJar) { - destinationDirectory = file("build/tmp") - classifier = 'tmpBridge' - configurations = [project.configurations."shadowBridge$_flavor"] - - include 'org/spongepowered/asm/bridge/RemapperAdapter.class' - include 'org/spongepowered/asm/bridge/RemapperAdapterFML.class' - } - - // 3. Combine the two jars - task("shadowJar$_flavor", type: ShadowJar) { - from(sourceSets.main.output) { - exclude "mcmod.info" - } - - version = versionBase + "+" + mixinFlavorClassifier - - dependsOn "mixinJar$_flavor" - dependsOn "bridgeJar$_flavor" - - from zipTree(tasks."mixinJar$_flavor".archiveFile).matching { - exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.MF" - exclude "META-INF/services/*.Processor" - // Replaced by local classes - exclude "org/spongepowered/asm/bridge/**" - } - from zipTree(tasks."bridgeJar$_flavor".archiveFile).matching { include 'org/spongepowered/asm/bridge/*' } - - doLast { - delete tasks."mixinJar$_flavor".archiveFile - delete tasks."bridgeJar$_flavor".archiveFile - } - - manifest { - attributes( - 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker', - 'FMLCorePluginContainsFMLMod': 'true', - 'ForceLoadAsMod': 'true', - ) - } - } - jar.dependsOn("shadowJar$_flavor") }