[Gradle, Kapt] Run kapt even when all dependencies are indirect
Previously, kapt skipped the execution, if the "kapt" configuration had no direct dependencies (via `kapt.dependencies.isEmpty()`). This lead to kapt not working, if all annotation processors are declared in a super-configuration of kapt. With this change, we also consider super-configurations (via `kapt.allDependencies.isEmpty`) and fix the described bug. ^KT-62518 Fixed
This commit is contained in:
committed by
Space Team
parent
fb8bf19091
commit
cf8b41970e
+10
@@ -159,6 +159,16 @@ open class Kapt3IT : Kapt3BaseIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Kapt is not skipped when all annotation processors are declared as indirect dependencies")
|
||||||
|
@GradleTest
|
||||||
|
fun testKaptNotSkippedWithIndirectDependencies(gradleVersion: GradleVersion) {
|
||||||
|
project("indirectDependencies".withPrefix, gradleVersion) {
|
||||||
|
build("assemble") {
|
||||||
|
assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("Kapt is working with newer JDKs")
|
@DisplayName("Kapt is working with newer JDKs")
|
||||||
@JdkVersions(versions = [JavaVersion.VERSION_1_10, JavaVersion.VERSION_11, JavaVersion.VERSION_16, JavaVersion.VERSION_17])
|
@JdkVersions(versions = [JavaVersion.VERSION_1_10, JavaVersion.VERSION_11, JavaVersion.VERSION_16, JavaVersion.VERSION_17])
|
||||||
@GradleWithJdkTest
|
@GradleWithJdkTest
|
||||||
|
|||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "java"
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
id "org.jetbrains.kotlin.kapt"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
baseAnnos
|
||||||
|
kapt.extendsFrom(baseAnnos)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
implementation "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||||
|
baseAnnos "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named("compileKotlin", KotlinJvmCompile) {
|
||||||
|
compilerOptions.allWarningsAsErrors = false // compilation with LV=2.0 prints warning about kapt fallback
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
@example.ExampleAnnotation
|
||||||
|
@example.ExampleSourceAnnotation
|
||||||
|
@example.ExampleBinaryAnnotation
|
||||||
|
@example.ExampleRuntimeAnnotation
|
||||||
|
public class TestClass {
|
||||||
|
|
||||||
|
@example.ExampleAnnotation
|
||||||
|
public val testVal: String = "text"
|
||||||
|
|
||||||
|
}
|
||||||
+1
-2
@@ -277,7 +277,7 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
|||||||
|
|
||||||
val kaptExtension = project.extensions.getByType(KaptExtension::class.java)
|
val kaptExtension = project.extensions.getByType(KaptExtension::class.java)
|
||||||
|
|
||||||
val nonEmptyKaptConfigurations = kaptConfigurations.filter { it.dependencies.isNotEmpty() }
|
val nonEmptyKaptConfigurations = kaptConfigurations.filter { it.allDependencies.isNotEmpty() }
|
||||||
|
|
||||||
val javaCompileOrNull = findJavaTaskForKotlinCompilation(kotlinCompilation)
|
val javaCompileOrNull = findJavaTaskForKotlinCompilation(kotlinCompilation)
|
||||||
|
|
||||||
@@ -359,7 +359,6 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
|||||||
generateStubsTask: TaskProvider<KaptGenerateStubsTask>
|
generateStubsTask: TaskProvider<KaptGenerateStubsTask>
|
||||||
): TaskProvider<out KaptTask> {
|
): TaskProvider<out KaptTask> {
|
||||||
val taskName = kotlinCompile.kaptTaskName
|
val taskName = kotlinCompile.kaptTaskName
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val taskConfigAction = KaptWithoutKotlincConfig(
|
val taskConfigAction = KaptWithoutKotlincConfig(
|
||||||
kotlinCompilation.project,
|
kotlinCompilation.project,
|
||||||
generateStubsTask,
|
generateStubsTask,
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("FunctionName")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.regressionTests
|
||||||
|
|
||||||
|
import org.gradle.api.NamedDomainObjectProvider
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin
|
||||||
|
import org.jetbrains.kotlin.gradle.util.buildProjectWithJvm
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
class KT62518KaptWorksWithIndirectDeps {
|
||||||
|
@Test
|
||||||
|
fun `let kapt extend from another configuration`() {
|
||||||
|
val project = buildProjectWithJvm {
|
||||||
|
plugins.apply(Kapt3GradleSubplugin::class.java)
|
||||||
|
}
|
||||||
|
val dep = project.dependencies.create("unresolved:dependency")
|
||||||
|
val baseConfig: NamedDomainObjectProvider<Configuration> = project.configurations.register("baseConfig") {
|
||||||
|
it.dependencies.add(dep)
|
||||||
|
}
|
||||||
|
project.configurations.named(Kapt3GradleSubplugin.MAIN_KAPT_CONFIGURATION_NAME) {
|
||||||
|
it.extendsFrom(baseConfig.get())
|
||||||
|
}
|
||||||
|
project.evaluate()
|
||||||
|
|
||||||
|
val taskSpecificConfig = project.configurations.getByName("kaptClasspath_kaptKotlin")
|
||||||
|
|
||||||
|
assert(dep in taskSpecificConfig.allDependencies)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user