From dc454f4483b76cd5f00e0de9891ee1487eb01d37 Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Wed, 12 Apr 2023 01:01:10 +0100 Subject: [PATCH] Update Kotlin to 1.8.20 Also Gradle to 8.0, new version of publish plugin and I hope everything still works correctly in FIR. --- .gitignore | 1 + README.md | 4 +-- build.gradle | 10 +++--- gradle-plugin/build.gradle | 33 +++---------------- .../me/shika/ObjectSerializationPlugin.kt | 2 +- gradle/utils/embedded.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- integration-test/build.gradle | 2 ++ kotlin-plugin/build.gradle | 9 +---- .../kotlin/me/shika/CommandLineProcessor.kt | 2 ++ .../kotlin/me/shika/ComponentRegistrar.kt | 14 ++++---- ...in.compiler.plugin.CompilerPluginRegistrar | 1 + ....kotlin.compiler.plugin.ComponentRegistrar | 1 - .../me/shika/ObjectSerializationFixTest.kt | 12 ++++--- settings.gradle | 10 ++++++ 15 files changed, 49 insertions(+), 56 deletions(-) create mode 100644 kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar delete mode 100644 kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar diff --git a/.gitignore b/.gitignore index 66bceac..6d9a9e5 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ gradle-app.setting # gradle/wrapper/gradle-wrapper.properties .DS_Store +local.properties \ No newline at end of file diff --git a/README.md b/README.md index 145fade..fde8ee6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The plugin adds `readResolve` method for every object which either: // plugins dsl plugins { - id "me.shika.kotlin-object-java-serialization" version "1.4.1" + id "me.shika.kotlin-object-java-serialization" version "1.4.2" } // or else @@ -25,7 +25,7 @@ buildscript { } } dependencies { - classpath "me.shika:kotlin-object-java-serialization:1.4.1" + classpath "me.shika:kotlin-object-java-serialization:1.4.2" } } diff --git a/build.gradle b/build.gradle index b42e0bc..08257c3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,8 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.7.21' + id 'org.jetbrains.kotlin.jvm' version '1.8.20' } -sourceCompatibility = 1.8 - allprojects { repositories { mavenLocal() @@ -13,5 +11,9 @@ allprojects { } group 'me.shika' - version '1.4.1' + version '1.4.2' + + kotlin { + jvmToolchain(11) + } } diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index eb05950..e711846 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.gradle.plugin-publish' version '0.18.0' + id 'com.gradle.plugin-publish' version '1.2.0' id 'maven-publish' id 'java-gradle-plugin' id 'org.jetbrains.kotlin.jvm' @@ -7,40 +7,17 @@ plugins { apply from: rootProject.file('gradle/utils/embedded.gradle') -pluginBundle { +gradlePlugin { website = 'https://github.com/ShikaSD/kotlin-object-serialization-fix' vcsUrl = 'https://github.com/ShikaSD/kotlin-object-serialization-fix.git' - plugins { - objectSerialization { - displayName = "Java serialization fix for Kotlin object" - description = "Solves the problem of Kotlin object being having different instance after deserialization using built-in Java serialization." - tags = ['kotlin', 'compiler-plugin', 'java', 'serialization'] - } - } - - mavenCoordinates { - groupId = project.getGroup() - artifactId = "kotlin-object-java-serialization" - version = project.getVersion() - } -} - -publishing { - afterEvaluate { - publications { - withType(MavenPublication) { - artifactId "kotlin-object-java-serialization" - } - } - } -} - -gradlePlugin { plugins { objectSerialization { id = "me.shika.kotlin-object-java-serialization" implementationClass = "me.shika.ObjectSerializationPlugin" + displayName = "Java serialization fix for Kotlin object" + description = "Solves the problem of Kotlin object being having different instance after deserialization using built-in Java serialization." + tags.set(['kotlin', 'compiler-plugin', 'java', 'serialization']) } } } diff --git a/gradle-plugin/src/main/kotlin/me/shika/ObjectSerializationPlugin.kt b/gradle-plugin/src/main/kotlin/me/shika/ObjectSerializationPlugin.kt index de40605..a46fcea 100644 --- a/gradle-plugin/src/main/kotlin/me/shika/ObjectSerializationPlugin.kt +++ b/gradle-plugin/src/main/kotlin/me/shika/ObjectSerializationPlugin.kt @@ -36,7 +36,7 @@ class ObjectSerializationPlugin : KotlinCompilerPluginSupportPlugin { SubpluginArtifact( groupId = "me.shika", artifactId = "kotlin-object-java-serialization", - version = "1.4.1" + version = "1.4.2" ) override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = diff --git a/gradle/utils/embedded.gradle b/gradle/utils/embedded.gradle index b97d9e9..216a871 100644 --- a/gradle/utils/embedded.gradle +++ b/gradle/utils/embedded.gradle @@ -29,7 +29,7 @@ afterEvaluate { } } - task sourcesJar(type: Jar) { + tasks.getByName("sourcesJar") { archiveClassifier = 'sources' from embeddedProjects().collect { it.sourceSets.main.allSource } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..e1bef7e 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.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/integration-test/build.gradle b/integration-test/build.gradle index 445feb6..daf228f 100644 --- a/integration-test/build.gradle +++ b/integration-test/build.gradle @@ -1,5 +1,7 @@ plugins { id 'org.jetbrains.kotlin.jvm' + // Use for testing maven local +// id 'me.shika.kotlin-object-java-serialization' version '1.4.2' } dependencies { diff --git a/kotlin-plugin/build.gradle b/kotlin-plugin/build.gradle index c75014c..887317a 100644 --- a/kotlin-plugin/build.gradle +++ b/kotlin-plugin/build.gradle @@ -10,14 +10,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable" - testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.4.9' + testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0' testImplementation 'junit:junit:4.12' testImplementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable' } - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} diff --git a/kotlin-plugin/src/main/kotlin/me/shika/CommandLineProcessor.kt b/kotlin-plugin/src/main/kotlin/me/shika/CommandLineProcessor.kt index baaebb4..1cc3304 100644 --- a/kotlin-plugin/src/main/kotlin/me/shika/CommandLineProcessor.kt +++ b/kotlin-plugin/src/main/kotlin/me/shika/CommandLineProcessor.kt @@ -3,10 +3,12 @@ package me.shika import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption import org.jetbrains.kotlin.compiler.plugin.CliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfigurationKey //@AutoService(CommandLineProcessor::class) +@OptIn(ExperimentalCompilerApi::class) class ObjectSerializationCommandLineProcessor : CommandLineProcessor { override val pluginId: String = "object-serialization-fix" override val pluginOptions: Collection = diff --git a/kotlin-plugin/src/main/kotlin/me/shika/ComponentRegistrar.kt b/kotlin-plugin/src/main/kotlin/me/shika/ComponentRegistrar.kt index a20272f..bf38a41 100644 --- a/kotlin-plugin/src/main/kotlin/me/shika/ComponentRegistrar.kt +++ b/kotlin-plugin/src/main/kotlin/me/shika/ComponentRegistrar.kt @@ -5,23 +5,25 @@ import me.shika.generation.ObjectSerializationIrGeneration import me.shika.generation.ObjectSerializationJvmGeneration import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension -import org.jetbrains.kotlin.com.intellij.mock.MockProject -import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar +import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.jetbrains.kotlin.config.CompilerConfiguration -class ObjectSerializationComponentRegistrar(): ComponentRegistrar { - override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { +@OptIn(ExperimentalCompilerApi::class) +class ObjectSerializationCompilerPluginRegistrar : CompilerPluginRegistrar() { + override val supportsK2: Boolean + get() = true + + override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { if (configuration[KEY_ENABLED] == false) { return } ExpressionCodegenExtension.registerExtension( - project, ObjectSerializationJvmGeneration() ) IrGenerationExtension.registerExtension( - project, ObjectSerializationIrGeneration() ) } diff --git a/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar b/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar new file mode 100644 index 0000000..3637c34 --- /dev/null +++ b/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar @@ -0,0 +1 @@ +me.shika.ObjectSerializationCompilerPluginRegistrar diff --git a/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar deleted file mode 100644 index 674959c..0000000 --- a/kotlin-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar +++ /dev/null @@ -1 +0,0 @@ -me.shika.ObjectSerializationComponentRegistrar diff --git a/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt b/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt index e96cece..697df7d 100644 --- a/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt +++ b/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt @@ -2,6 +2,7 @@ package me.shika import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith @@ -9,17 +10,20 @@ import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameters import java.lang.reflect.Method +@OptIn(ExperimentalCompilerApi::class) @RunWith(Parameterized::class) -class ObjectSerializationFixTest(enableIr: Boolean) { +class ObjectSerializationFixTest(enableIr: Boolean, enableFir: Boolean) { companion object { - @Parameters(name = "IR: {0}") + @Parameters(name = "IR: {0}, FIR: {1}") @JvmStatic - fun data() = listOf(false, true) + fun data() = arrayOf(arrayOf(false, false), arrayOf(true, false), arrayOf(true, true)) } private val compiler = KotlinCompilation().apply { - compilerPlugins = listOf(ObjectSerializationComponentRegistrar()) + compilerPluginRegistrars = listOf(ObjectSerializationCompilerPluginRegistrar()) useIR = enableIr + supportsK2 = true + useK2 = enableFir } private val SERIALIZABLE_OBJECT = """ diff --git a/settings.gradle b/settings.gradle index 83d18df..b1c298a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,16 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + mavenCentral() + } +} + rootProject.name = 'kotlin-object-java-serialization' include ':gradle-plugin' include ':kotlin-plugin' include ':integration-test' include ':integration-test:scala-module' + +project(':gradle-plugin').name = "kotlin-object-java-serialization"