mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-20 15:52:36 +00:00
Add back empty stub implementations of KotlinGradleSubplugin (KT-39809)
* If a KotlinGradleSubplugin implements KotlinCompilerPluginSupportPlugin, don't apply it as a legacy plugin * Add the legacy KotlinGradleSubplugin implementations back so that when there's JAR hell with META-INF/services in the old artifacts pointing to the classes, loading the plugins with ServiceLoader (legacy implementation) from the new artifacts would not fail. * There's a corner case for plugins not in kotlin-gradle-plugin If a newer and older version of such a subplugin is used with an older version of the Kotlin Gradle plugin, the latter will find the META-INF entries and will try to load the subplugins from the new version. With the original fix for KT-39809, this would result in silently ignored empty stub implementations. Given that the Kotlin Gradle plugin can now check if a subplugin supports the new API, it's OK to keep the old entries and make the stub implementations throw a build error when called, so that improper plugin versions are not ignored and are clearly reported. Note that this is only necessary for the subplugins not bundled in the kotlin-gradle-plugin module, as those will always be in sync with the Kotlin version. Issue #KT-39809 Fixed
This commit is contained in:
@@ -16,15 +16,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.allopen.gradle
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.allopen.gradle.model.builder.AllOpenModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AllOpenGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
|
||||
KotlinCompilerPluginSupportPlugin {
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile> {
|
||||
|
||||
companion object {
|
||||
fun getAllOpenExtension(project: Project): AllOpenExtension {
|
||||
return project.extensions.getByType(AllOpenExtension::class.java)
|
||||
@@ -68,4 +75,21 @@ class AllOpenGradleSubplugin @Inject internal constructor(private val registry:
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlin.allopen"
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = ALLOPEN_ARTIFACT_NAME)
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
internal constructor(): this(object : ToolingModelBuilderRegistry {
|
||||
override fun register(p0: ToolingModelBuilder) = Unit
|
||||
override fun getBuilder(p0: String): ToolingModelBuilder? = null
|
||||
})
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = true
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = throw GradleException(
|
||||
"This version of the kotlin-allopen Gradle plugin is built for a newer Kotlin version. " +
|
||||
"Please use an older version of kotlin-allopen or upgrade the Kotlin version to make them match."
|
||||
)
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.allopen.gradle.AllOpenGradleSubplugin
|
||||
@@ -123,7 +123,7 @@ interface KotlinCompilerPluginSupportPlugin : Plugin<Project> {
|
||||
|
||||
fun getCompilerPluginId(): String
|
||||
fun getPluginArtifact(): SubpluginArtifact
|
||||
fun getNativeCompilerPluginArtifact(): SubpluginArtifact? = null
|
||||
fun getPluginArtifactForNative(): SubpluginArtifact? = null
|
||||
}
|
||||
|
||||
open class SubpluginArtifact(val groupId: String, val artifactId: String, val version: String? = null)
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.util.checkBytecodeContains
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SubpluginsIT : BaseGradleIT() {
|
||||
@@ -193,4 +191,62 @@ class SubpluginsIT : BaseGradleIT() {
|
||||
assertFileExists("${kotlinClassesDir(sourceSet = "test")}MyTestClass.class")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinVersionDowngradeInSupbrojectKt39809() = with(Project("multiprojectWithDependency")) {
|
||||
setupWorkingDir()
|
||||
|
||||
projectDir.resolve("projA/build.gradle").modify {
|
||||
"""
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.70")
|
||||
}
|
||||
}
|
||||
|
||||
$it
|
||||
""".trimIndent()
|
||||
}
|
||||
build(":projA:compileKotlin") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinVersionDowngradeWithNewerSubpluginsKt39809() = with(Project("multiprojectWithDependency")) {
|
||||
setupWorkingDir()
|
||||
|
||||
val subprojectBuildGradle = projectDir.resolve("projA/build.gradle")
|
||||
val originalScript = subprojectBuildGradle.readText()
|
||||
|
||||
listOf("allopen", "noarg", "sam-with-receiver", "serialization").forEach { plugin ->
|
||||
projectDir.resolve("projA/build.gradle").modify {
|
||||
"""
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-$plugin:${defaultBuildOptions().kotlinVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "org.jetbrains.kotlin.plugin.${plugin.replace("-", ".")}"
|
||||
|
||||
$originalScript
|
||||
""".trimIndent()
|
||||
}
|
||||
build(":projA:compileKotlin", options = defaultBuildOptions().copy(kotlinVersion = "1.3.72")) {
|
||||
assertFailed()
|
||||
assertContains(
|
||||
"This version of the kotlin-$plugin Gradle plugin is built for a newer Kotlin version. " +
|
||||
"Please use an older version of kotlin-$plugin or upgrade the Kotlin version to make them match."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,9 @@ import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.process.CommandLineArgumentProvider
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.CLASS_STRUCTURE_ARTIFACT_TYPE
|
||||
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.StructureArtifactTransform
|
||||
import org.jetbrains.kotlin.gradle.model.builder.KaptModelBuilder
|
||||
@@ -41,7 +43,9 @@ import javax.inject.Inject
|
||||
|
||||
// apply plugin: 'kotlin-kapt'
|
||||
class Kapt3GradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
|
||||
KotlinCompilerPluginSupportPlugin {
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile> {
|
||||
|
||||
override fun apply(target: Project) {
|
||||
target.extensions.create("kapt", KaptExtension::class.java)
|
||||
@@ -587,6 +591,20 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = KAPT_ARTIFACT_NAME)
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
internal constructor(): this(object : ToolingModelBuilderRegistry {
|
||||
override fun register(p0: ToolingModelBuilder) = Unit
|
||||
override fun getBuilder(p0: String): ToolingModelBuilder? = null
|
||||
})
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = false
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = emptyList()
|
||||
//endregion
|
||||
}
|
||||
private val artifactType = Attribute.of("artifactType", String::class.java)
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ class SubpluginEnvironment(
|
||||
val result = project.plugins.filterIsInstance<KotlinCompilerPluginSupportPlugin>()
|
||||
|
||||
@Suppress("DEPRECATION", "UNCHECKED_CAST")
|
||||
val compatibilitySubplugins = ServiceLoader.load(klass, classloader).map {
|
||||
LegacyKotlinCompilerPluginSupportPlugin(it as KotlinGradleSubplugin<AbstractCompile>)
|
||||
}
|
||||
val compatibilitySubplugins = ServiceLoader.load(klass, classloader)
|
||||
.filter { it !is KotlinCompilerPluginSupportPlugin }
|
||||
.map { LegacyKotlinCompilerPluginSupportPlugin(it as KotlinGradleSubplugin<AbstractCompile>) }
|
||||
|
||||
SubpluginEnvironment(result + compatibilitySubplugins, kotlinPluginVersion)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
@@ -70,7 +70,7 @@ class SubpluginEnvironment(
|
||||
project.addMavenDependency(PLUGIN_CLASSPATH_CONFIGURATION_NAME, artifact)
|
||||
}
|
||||
|
||||
subplugin.getNativeCompilerPluginArtifact()?.let { artifact ->
|
||||
subplugin.getPluginArtifactForNative()?.let { artifact ->
|
||||
project.addMavenDependency(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME, artifact)
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ internal class LegacyKotlinCompilerPluginSupportPlugin(
|
||||
|
||||
override fun getCompilerPluginId(): String = oldPlugin.getCompilerPluginId()
|
||||
override fun getPluginArtifact(): SubpluginArtifact = oldPlugin.getPluginArtifact()
|
||||
override fun getNativeCompilerPluginArtifact(): SubpluginArtifact? = oldPlugin.getNativeCompilerPluginArtifact()
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact? = oldPlugin.getNativeCompilerPluginArtifact()
|
||||
}
|
||||
|
||||
internal fun findJavaTaskForKotlinCompilation(compilation: KotlinCompilation<*>): TaskProvider<out JavaCompile>? =
|
||||
|
||||
@@ -14,8 +14,10 @@ import org.gradle.api.artifacts.transform.ArtifactTransform
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.plugins.JavaPluginConvention
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
@@ -207,7 +209,10 @@ fun Configuration.discoverScriptExtensionsFiles() =
|
||||
}.artifacts.artifactFiles
|
||||
|
||||
|
||||
class ScriptingKotlinGradleSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
class ScriptingKotlinGradleSubplugin :
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<KotlinCompile> {
|
||||
companion object {
|
||||
const val SCRIPTING_ARTIFACT_NAME = "kotlin-scripting-compiler-embeddable"
|
||||
|
||||
@@ -250,4 +255,13 @@ class ScriptingKotlinGradleSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
override fun getCompilerPluginId() = "kotlin.scripting"
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = SCRIPTING_ARTIFACT_NAME)
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = false
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: KotlinCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = emptyList()
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.model.builder.KotlinAndroidExtensionModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
||||
@@ -65,7 +67,11 @@ class AndroidExtensionsSubpluginIndicator @Inject internal constructor(private v
|
||||
}
|
||||
}
|
||||
|
||||
class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
class AndroidSubplugin :
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile>
|
||||
{
|
||||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
|
||||
if (kotlinCompilation !is KotlinJvmAndroidCompilation)
|
||||
return false
|
||||
@@ -284,4 +290,13 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
val builder = factory.newDocumentBuilder()
|
||||
return builder.parse(this)
|
||||
}
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = false
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = emptyList()
|
||||
//endregion
|
||||
}
|
||||
@@ -16,15 +16,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.noarg.gradle
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.noarg.gradle.model.builder.NoArgModelBuilder
|
||||
import javax.inject.Inject
|
||||
|
||||
class NoArgGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
|
||||
KotlinCompilerPluginSupportPlugin {
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile> {
|
||||
|
||||
companion object {
|
||||
fun getNoArgExtension(project: Project): NoArgExtension {
|
||||
@@ -73,4 +79,21 @@ class NoArgGradleSubplugin @Inject internal constructor(private val registry: To
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlin.noarg"
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = NOARG_ARTIFACT_NAME)
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
internal constructor(): this(object : ToolingModelBuilderRegistry {
|
||||
override fun register(p0: ToolingModelBuilder) = Unit
|
||||
override fun getBuilder(p0: String): ToolingModelBuilder? = null
|
||||
})
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = true
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = throw GradleException(
|
||||
"This version of the kotlin-noarg Gradle plugin is built for a newer Kotlin version. " +
|
||||
"Please use an older version of kotlin-noarg or upgrade the Kotlin version to make them match."
|
||||
)
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.noarg.gradle.NoArgGradleSubplugin
|
||||
@@ -16,14 +16,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.samWithReceiver.gradle
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.noarg.gradle.model.builder.SamWithReceiverModelBuilder
|
||||
import javax.inject.Inject
|
||||
|
||||
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : KotlinCompilerPluginSupportPlugin {
|
||||
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile> {
|
||||
|
||||
override fun apply(target: Project) {
|
||||
target.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java)
|
||||
registry.register(SamWithReceiverModelBuilder())
|
||||
@@ -64,4 +72,21 @@ class SamWithReceiverGradleSubplugin @Inject internal constructor(private val re
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlin.samWithReceiver"
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = SAM_WITH_RECEIVER_ARTIFACT_NAME)
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
internal constructor(): this(object : ToolingModelBuilderRegistry {
|
||||
override fun register(p0: ToolingModelBuilder) = Unit
|
||||
override fun getBuilder(p0: String): ToolingModelBuilder? = null
|
||||
})
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = true
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = throw GradleException(
|
||||
"This version of the kotlin-sam-with-receiver Gradle plugin is built for a newer Kotlin version. " +
|
||||
"Please use an older version of kotlin-sam-with-receiver or upgrade the Kotlin version to make them match."
|
||||
)
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverGradleSubplugin
|
||||
@@ -15,7 +15,7 @@ compileJava {
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':kotlin-gradle-plugin')
|
||||
compileOnly project(':kotlin-gradle-plugin-api')
|
||||
compile project(':kotlin-gradle-plugin-api')
|
||||
|
||||
compileOnly kotlinStdlib()
|
||||
compileOnly project(path: ':kotlin-compiler-embeddable', configuration: 'runtimeJar')
|
||||
|
||||
@@ -16,13 +16,21 @@
|
||||
|
||||
package org.jetbrains.kotlinx.serialization.gradle
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
class SerializationGradleSubplugin :
|
||||
KotlinCompilerPluginSupportPlugin,
|
||||
@Suppress("DEPRECATION") // implementing to fix KT-39809
|
||||
KotlinGradleSubplugin<AbstractCompile> {
|
||||
|
||||
class SerializationGradleSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
companion object {
|
||||
const val SERIALIZATION_GROUP_NAME = "org.jetbrains.kotlin"
|
||||
const val SERIALIZATION_ARTIFACT_NAME = "kotlin-serialization"
|
||||
@@ -39,8 +47,20 @@ class SerializationGradleSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
SubpluginArtifact(SERIALIZATION_GROUP_NAME, SERIALIZATION_ARTIFACT_NAME)
|
||||
|
||||
override fun getNativeCompilerPluginArtifact(): SubpluginArtifact? =
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact? =
|
||||
SubpluginArtifact(SERIALIZATION_GROUP_NAME, SERIALIZATION_ARTIFACT_UNSHADED_NAME)
|
||||
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlinx.serialization"
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean = true
|
||||
|
||||
override fun apply(
|
||||
project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<KotlinCommonOptions>?
|
||||
): List<SubpluginOption> = throw GradleException(
|
||||
"This version of the kotlin-serialization Gradle plugin is built for a newer Kotlin version. " +
|
||||
"Please use an older version of kotlin-serialization or upgrade the Kotlin version to make them match."
|
||||
)
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin
|
||||
Reference in New Issue
Block a user