From aa7327dca5904bca56806d7008b4e611ea1d0b40 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 27 Nov 2024 22:23:57 +0000 Subject: [PATCH 1/4] Use the stable kotlin-metadata since Kotlin 2 --- gradle/libs.versions.toml | 3 +- .../loom/util/LibraryLocationLogger.java | 2 +- .../loom/util/kotlin/KotlinPluginUtils.java | 2 +- ...ClassMetadataRemappingAnnotationVisitor.kt | 4 +- .../kotlin/remapping/KotlinClassRemapper.kt | 56 +++++++++---------- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0a63f4d9d..41500ffe5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,6 @@ access-widener = "2.1.0" mapping-io = "0.6.1" lorenz-tiny = "4.0.2" mercury = "0.4.2" -kotlinx-metadata = "0.9.0" loom-native = "0.2.0" # Plugins @@ -42,7 +41,7 @@ fabric-loom-nativelib = { module = "net.fabricmc:fabric-loom-native", version.re # Misc kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -kotlin-metadata = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version.ref = "kotlinx-metadata" } +kotlin-metadata = { module = "org.jetbrains.kotlin:kotlin-metadata-jvm", version.ref = "kotlin" } [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/src/main/java/net/fabricmc/loom/util/LibraryLocationLogger.java b/src/main/java/net/fabricmc/loom/util/LibraryLocationLogger.java index ce193de42..1d328c578 100644 --- a/src/main/java/net/fabricmc/loom/util/LibraryLocationLogger.java +++ b/src/main/java/net/fabricmc/loom/util/LibraryLocationLogger.java @@ -28,7 +28,7 @@ import com.google.common.base.Preconditions; import com.google.gson.Gson; -import kotlinx.metadata.jvm.KotlinClassMetadata; +import kotlin.metadata.jvm.KotlinClassMetadata; import org.apache.commons.io.FileUtils; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.commons.ClassRemapper; diff --git a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java index 76a96215c..ac6250e45 100644 --- a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java +++ b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java @@ -29,7 +29,7 @@ import java.io.UncheckedIOException; import java.util.Properties; -import kotlinx.metadata.jvm.KotlinClassMetadata; +import kotlin.metadata.jvm.KotlinClassMetadata; import org.gradle.api.Project; public class KotlinPluginUtils { diff --git a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt index 483d9f6d8..7618e778e 100644 --- a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt +++ b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt @@ -24,8 +24,8 @@ package net.fabricmc.loom.kotlin.remapping -import kotlinx.metadata.jvm.KotlinClassMetadata -import kotlinx.metadata.jvm.Metadata +import kotlin.metadata.jvm.KotlinClassMetadata +import kotlin.metadata.jvm.Metadata import org.objectweb.asm.AnnotationVisitor import org.objectweb.asm.Opcodes import org.objectweb.asm.commons.Remapper diff --git a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt index d77a0d48f..9548a2093 100644 --- a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt +++ b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt @@ -24,34 +24,34 @@ package net.fabricmc.loom.kotlin.remapping -import kotlinx.metadata.ClassName -import kotlinx.metadata.ExperimentalContextReceivers -import kotlinx.metadata.KmAnnotation -import kotlinx.metadata.KmClass -import kotlinx.metadata.KmClassifier -import kotlinx.metadata.KmConstructor -import kotlinx.metadata.KmFlexibleTypeUpperBound -import kotlinx.metadata.KmFunction -import kotlinx.metadata.KmLambda -import kotlinx.metadata.KmPackage -import kotlinx.metadata.KmProperty -import kotlinx.metadata.KmType -import kotlinx.metadata.KmTypeAlias -import kotlinx.metadata.KmTypeParameter -import kotlinx.metadata.KmTypeProjection -import kotlinx.metadata.KmValueParameter -import kotlinx.metadata.isLocalClassName -import kotlinx.metadata.jvm.JvmFieldSignature -import kotlinx.metadata.jvm.JvmMethodSignature -import kotlinx.metadata.jvm.annotations -import kotlinx.metadata.jvm.fieldSignature -import kotlinx.metadata.jvm.getterSignature -import kotlinx.metadata.jvm.localDelegatedProperties -import kotlinx.metadata.jvm.setterSignature -import kotlinx.metadata.jvm.signature -import kotlinx.metadata.jvm.syntheticMethodForAnnotations -import kotlinx.metadata.jvm.syntheticMethodForDelegate -import kotlinx.metadata.jvm.toJvmInternalName +import kotlin.metadata.ClassName +import kotlin.metadata.ExperimentalContextReceivers +import kotlin.metadata.KmAnnotation +import kotlin.metadata.KmClass +import kotlin.metadata.KmClassifier +import kotlin.metadata.KmConstructor +import kotlin.metadata.KmFlexibleTypeUpperBound +import kotlin.metadata.KmFunction +import kotlin.metadata.KmLambda +import kotlin.metadata.KmPackage +import kotlin.metadata.KmProperty +import kotlin.metadata.KmType +import kotlin.metadata.KmTypeAlias +import kotlin.metadata.KmTypeParameter +import kotlin.metadata.KmTypeProjection +import kotlin.metadata.KmValueParameter +import kotlin.metadata.isLocalClassName +import kotlin.metadata.jvm.JvmFieldSignature +import kotlin.metadata.jvm.JvmMethodSignature +import kotlin.metadata.jvm.annotations +import kotlin.metadata.jvm.fieldSignature +import kotlin.metadata.jvm.getterSignature +import kotlin.metadata.jvm.localDelegatedProperties +import kotlin.metadata.jvm.setterSignature +import kotlin.metadata.jvm.signature +import kotlin.metadata.jvm.syntheticMethodForAnnotations +import kotlin.metadata.jvm.syntheticMethodForDelegate +import kotlin.metadata.jvm.toJvmInternalName import org.objectweb.asm.commons.Remapper @OptIn(ExperimentalContextReceivers::class) From b4e4e495d66f1e8cdb6226bb8333643ca6503b3e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 27 Nov 2024 22:31:31 +0000 Subject: [PATCH 2/4] More fixes --- .../fabricmc/loom/util/kotlin/KotlinClasspathService.java | 7 +++---- .../net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java | 5 ----- src/test/resources/projects/kotlin/build.gradle.kts | 8 ++++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinClasspathService.java b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinClasspathService.java index 9672dc90c..3f89a7f5f 100644 --- a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinClasspathService.java +++ b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinClasspathService.java @@ -61,17 +61,16 @@ public static Provider createOptions(Project project) { return createOptions( project, - KotlinPluginUtils.getKotlinPluginVersion(project), - KotlinPluginUtils.getKotlinMetadataVersion() + KotlinPluginUtils.getKotlinPluginVersion(project) ); } - private static Provider createOptions(Project project, String kotlinVersion, String kotlinMetadataVersion) { + private static Provider createOptions(Project project, String kotlinVersion) { // Create a detached config to resolve the kotlin std lib for the provided version. Configuration detachedConfiguration = project.getConfigurations().detachedConfiguration( project.getDependencies().create("org.jetbrains.kotlin:kotlin-stdlib:" + kotlinVersion), // Load kotlinx-metadata-jvm like this to work around: https://github.com/gradle/gradle/issues/14727 - project.getDependencies().create("org.jetbrains.kotlinx:kotlinx-metadata-jvm:" + kotlinMetadataVersion) + project.getDependencies().create("org.jetbrains.kotlin:kotlin-metadata-jvm:" + kotlinVersion) ); return TYPE.create(project, options -> { diff --git a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java index ac6250e45..8de617f36 100644 --- a/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java +++ b/src/main/java/net/fabricmc/loom/util/kotlin/KotlinPluginUtils.java @@ -29,7 +29,6 @@ import java.io.UncheckedIOException; import java.util.Properties; -import kotlin.metadata.jvm.KotlinClassMetadata; import org.gradle.api.Project; public class KotlinPluginUtils { @@ -56,8 +55,4 @@ private static String loadPropertyFromResources(Class kotlinPluginClass, Stri return props.getProperty(property); } - - public static String getKotlinMetadataVersion() { - return KotlinClassMetadata.class.getPackage().getImplementationVersion().split("-")[0]; - } } diff --git a/src/test/resources/projects/kotlin/build.gradle.kts b/src/test/resources/projects/kotlin/build.gradle.kts index 75a1015d2..37f00bb8c 100644 --- a/src/test/resources/projects/kotlin/build.gradle.kts +++ b/src/test/resources/projects/kotlin/build.gradle.kts @@ -3,8 +3,8 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions plugins { - kotlin("jvm") version "1.9.22" - kotlin("plugin.serialization") version "1.9.22" + kotlin("jvm") version "2.0.21" + kotlin("plugin.serialization") version "2.0.21" id("fabric-loom") `maven-publish` } @@ -31,8 +31,8 @@ version = "0.0.1" dependencies { minecraft(group = "com.mojang", name = "minecraft", version = "1.16.5") mappings(group = "net.fabricmc", name = "yarn", version = "1.16.5+build.5", classifier = "v2") - modImplementation("net.fabricmc:fabric-loader:0.12.12") - modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = "1.10.17+kotlin.1.9.22") + modImplementation("net.fabricmc:fabric-loader:0.16.9") + modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = "1.12.3+kotlin.2.0.21") } publishing { From 437804fe009aff091b30f56ff8ea60aabca0f8d1 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 27 Nov 2024 22:50:13 +0000 Subject: [PATCH 3/4] Fix build --- .../KotlinClassMetadataRemappingAnnotationVisitor.kt | 4 ++-- .../net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt index 7618e778e..b0736b7c7 100644 --- a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt +++ b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt @@ -24,13 +24,13 @@ package net.fabricmc.loom.kotlin.remapping -import kotlin.metadata.jvm.KotlinClassMetadata -import kotlin.metadata.jvm.Metadata import org.objectweb.asm.AnnotationVisitor import org.objectweb.asm.Opcodes import org.objectweb.asm.commons.Remapper import org.objectweb.asm.tree.AnnotationNode import org.slf4j.LoggerFactory +import kotlin.metadata.jvm.KotlinClassMetadata +import kotlin.metadata.jvm.Metadata class KotlinClassMetadataRemappingAnnotationVisitor( private val remapper: Remapper, diff --git a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt index 9548a2093..4cc9f42be 100644 --- a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt +++ b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassRemapper.kt @@ -24,6 +24,7 @@ package net.fabricmc.loom.kotlin.remapping +import org.objectweb.asm.commons.Remapper import kotlin.metadata.ClassName import kotlin.metadata.ExperimentalContextReceivers import kotlin.metadata.KmAnnotation @@ -52,7 +53,6 @@ import kotlin.metadata.jvm.signature import kotlin.metadata.jvm.syntheticMethodForAnnotations import kotlin.metadata.jvm.syntheticMethodForDelegate import kotlin.metadata.jvm.toJvmInternalName -import org.objectweb.asm.commons.Remapper @OptIn(ExperimentalContextReceivers::class) class KotlinClassRemapper(private val remapper: Remapper) { From faede889899aa3b13f53ddd1b15b06323bbd8424 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 28 Nov 2024 09:44:48 +0000 Subject: [PATCH 4/4] Fix unit test --- .../test/unit/kotlin/KotlinRemapperClassloaderTest.groovy | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/kotlin/KotlinRemapperClassloaderTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/kotlin/KotlinRemapperClassloaderTest.groovy index 98b4042a7..2c938ae9b 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/kotlin/KotlinRemapperClassloaderTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/kotlin/KotlinRemapperClassloaderTest.groovy @@ -30,7 +30,6 @@ import org.objectweb.asm.tree.ClassNode import spock.lang.Specification import net.fabricmc.loom.util.kotlin.KotlinClasspath -import net.fabricmc.loom.util.kotlin.KotlinPluginUtils import net.fabricmc.loom.util.kotlin.KotlinRemapperClassloader import net.fabricmc.tinyremapper.api.TrClass import net.fabricmc.tinyremapper.api.TrEnvironment @@ -38,9 +37,8 @@ import net.fabricmc.tinyremapper.api.TrRemapper class KotlinRemapperClassloaderTest extends Specification { private static String KOTLIN_VERSION = KotlinVersion.CURRENT.toString() - private static String KOTLIN_METADATA_VERSION = KotlinPluginUtils.kotlinMetadataVersion private static String KOTLIN_URL = "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/${KOTLIN_VERSION}/kotlin-stdlib-${KOTLIN_VERSION}.jar" - private static String KOTLIN_METADATA_URL = "https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-metadata-jvm/${KOTLIN_METADATA_VERSION}/kotlinx-metadata-jvm-${KOTLIN_METADATA_VERSION}.jar" + private static String KOTLIN_METADATA_URL = "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-metadata-jvm/${KOTLIN_VERSION}/kotlin-metadata-jvm-${KOTLIN_VERSION}.jar" def "Test Kotlin Remapper Classloader"() { given: