Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the stable kotlin-metadata #1222

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@ public static Provider<Options> createOptions(Project project) {

return createOptions(
project,
KotlinPluginUtils.getKotlinPluginVersion(project),
KotlinPluginUtils.getKotlinMetadataVersion()
KotlinPluginUtils.getKotlinPluginVersion(project)
);
}

private static Provider<Options> createOptions(Project project, String kotlinVersion, String kotlinMetadataVersion) {
private static Provider<Options> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.io.UncheckedIOException;
import java.util.Properties;

import kotlinx.metadata.jvm.KotlinClassMetadata;
import org.gradle.api.Project;

public class KotlinPluginUtils {
Expand All @@ -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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

package net.fabricmc.loom.kotlin.remapping

import kotlinx.metadata.jvm.KotlinClassMetadata
import kotlinx.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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@

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 org.objectweb.asm.commons.Remapper
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

@OptIn(ExperimentalContextReceivers::class)
class KotlinClassRemapper(private val remapper: Remapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ 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
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:
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/projects/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
Expand All @@ -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 {
Expand Down