From 079ecb341b09e1a69bd93f00e20b5f132f1f6d05 Mon Sep 17 00:00:00 2001 From: Username404 Date: Tue, 26 Oct 2021 12:04:34 +0200 Subject: [PATCH] Update gradle and make the buildscript compatible with architectury-loom 0.10+ --- build.gradle.kts | 32 +++++++++++++++++++----- forge/build.gradle.kts | 1 - gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index df9f0c0..27327ad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.modrinth.minotaur.request.VersionType +import net.fabricmc.loom.LoomGradleExtension +import net.fabricmc.loom.LoomGradlePlugin buildscript { dependencies { @@ -16,7 +18,7 @@ plugins { id("architectury-plugin") version "[3.0.100, 3.5[" id("dev.architectury.loom") version ( if (JavaVersion.current() >= JavaVersion.VERSION_16) - "[0.9.0.153, 0.9.1[" + "[0.9.0.153, 0.10.2[" else "[0.7.3.152, 0.7.4[" ) apply false id("com.github.ben-manes.versions") version "0.39.0" @@ -54,17 +56,35 @@ subprojects { lateinit var mappingsDep: Dependency apply(plugin = "dev.architectury.loom") apply(plugin = "org.jetbrains.kotlin.plugin.serialization") - extensions.configure("loom") { + extensions.configure("loom") { mappingsDep = layered { - officialMojangMappings().crane("dev.architectury:crane:${rootProject.architectury.minecraft}+build.+") + officialMojangMappings().parchment("org.parchmentmc.data:parchment-${rootProject.architectury.minecraft}:2021.10.17") } silentMojangMappingsLicense() - mixinConfig("snowygui-${project.name}.mixins.json") - refmapName = "snowygui-${project.name}-refmap.json" + val refmap = "snowygui-${project.name}-refmap.json" + // The following is used to make this buildscript compatible with architectury-loom 0.7.3, 0.9.X, 0.10.X and higher versions + with(javaClass) { + if (LoomGradlePlugin.LOOM_VERSION.run { + val numberPos = indexOf('.') + 1 + substring(numberPos, indexOf('.', numberPos)) + }.toDouble() < 10) { + getDeclaredMethod("setRefmapName", String::class.java).invoke(this@configure, refmap) + getDeclaredMethod("mixinConfig", String::class.java).invoke(this@configure, "snowygui-${project.name}.mixins.json") + } else { + getDeclaredMethod("getMixin").invoke(this@configure).run { + javaClass.getDeclaredMethod("getDefaultRefmapName").invoke(this).let { refmapProperty -> + refmapProperty.javaClass.getDeclaredMethod("set", Any::class.java).invoke(refmapProperty, refmap) + } + } + } + } } apply(plugin = "com.github.johnrengelman.shadow") val shadowC by configurations.creating - repositories { maven(url = "https://jitpack.io"); mavenCentral() } + repositories { + maven(url = "https://jitpack.io"); mavenCentral() + maven(url = "https://maven.parchmentmc.org") + } dependencies { implementation("$kotlinX:kotlinx-coroutines-jdk8:${rootProject.property("kotlin_coroutines_version")}") implementation("$kotlinX:kotlinx-serialization-core:$serializationVer") diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index d49d9f6..1f7a7f8 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { add("developmentForge", project(path = ":common")) { isTransitive = false } shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false } }; loom { - useFabricMixin = true if (JavaVersion.current().isJava9Compatible) { runs { val args: MutableList = mutableListOf("-Dfml.earlyprogresswindow=false") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..2b76039 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-rc-2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists