Fixup for the fix of KT-39809

In the original fix for KT-39809, the Kapt plugin was not given a proper
empty implementation stub: it was added to `Kapt3GradleSubplugin`, while
originally the Kapt subplugin's META-INF/services entry pointed to
`Kapt3KotlinGradleSubplugin`.

This commit makes the correct class implement the legacy interface.

Issue #KT-39809 Fixed
This commit is contained in:
Sergey Igushkin
2020-07-13 13:40:35 +04:00
parent 4c273e1fc5
commit 5ec93fd74c
2 changed files with 29 additions and 21 deletions
@@ -5,8 +5,10 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.gradle.util.checkBytecodeContains
import org.jetbrains.kotlin.gradle.util.modify
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Test
import java.io.File
import kotlin.test.assertTrue
@@ -193,10 +195,10 @@ class SubpluginsIT : BaseGradleIT() {
}
@Test
fun testKotlinVersionDowngradeInSupbrojectKt39809() = with(Project("multiprojectWithDependency")) {
fun testKotlinVersionDowngradeInSupbrojectKt39809() = with(Project("android-dagger", directoryPrefix = "kapt2")) {
setupWorkingDir()
projectDir.resolve("projA/build.gradle").modify {
gradleBuildScript("app").modify {
"""
buildscript {
repositories {
@@ -210,7 +212,13 @@ class SubpluginsIT : BaseGradleIT() {
$it
""".trimIndent()
}
build(":projA:compileKotlin") {
build(
":app:compileDebugKotlin",
options = defaultBuildOptions().copy(
androidGradlePluginVersion = AGPVersion.v3_4_1,
androidHome = KotlinTestUtils.findAndroidSdk()
)
) {
assertSuccessful()
}
}
@@ -43,9 +43,7 @@ import javax.inject.Inject
// apply plugin: 'kotlin-kapt'
class Kapt3GradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
KotlinCompilerPluginSupportPlugin,
@Suppress("DEPRECATION") // implementing to fix KT-39809
KotlinGradleSubplugin<AbstractCompile> {
KotlinCompilerPluginSupportPlugin {
override fun apply(target: Project) {
target.extensions.create("kapt", KaptExtension::class.java)
@@ -591,20 +589,6 @@ 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)
@@ -708,4 +692,20 @@ private val BaseVariant.dataBindingDependencyArtifactsIfSupported: FileCollectio
get() = this::class.java.methods
.find { it.name == "getDataBindingDependencyArtifacts" }
?.also { it.isAccessible = true }
?.invoke(this) as? FileCollection
?.invoke(this) as? FileCollection
//region Stub implementation for legacy API, KT-39809
@Suppress("DEPRECATION") // implementing to fix KT-39809
class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
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()
override fun getCompilerPluginId(): String = Kapt3GradleSubplugin.KAPT_SUBPLUGIN_ID
override fun getPluginArtifact(): SubpluginArtifact = JetBrainsSubpluginArtifact(artifactId = Kapt3GradleSubplugin.KAPT_ARTIFACT_NAME)
}
//endregion