KT-47347: Kapt processors should not be input files for stub generation
This commit avoids passing kapt processors as sources for stub generation task, and it also avoid using them as input files for stub generation. Instead, it adds a new property that simply records if processors are present (as going from empty to 1+ processors should re-run stubs). Fixes #KT-47347 Test: Kapt3IT.kt
This commit is contained in:
committed by
teamcityserver
parent
d564bfd450
commit
08c505f9ba
+27
@@ -27,6 +27,7 @@ import org.junit.Test
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipOutputStream
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
@@ -817,4 +818,30 @@ open class Kapt3IT : Kapt3BaseIT() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Regression test for https://youtrack.jetbrains.com/issue/KT-47347. */
|
||||
@Test
|
||||
fun testChangesToKaptConfigurationDoNotTriggerStubGeneration() {
|
||||
val project = Project("localAnnotationProcessor", directoryPrefix = "kapt2")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
ZipOutputStream(project.projectDir.resolve("fake_processor.jar").outputStream()).close()
|
||||
project.projectDir.resolve("example/build.gradle").appendText(
|
||||
"""
|
||||
|
||||
dependencies {
|
||||
kapt files("../fake_processor.jar")
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":example:kaptKotlin")
|
||||
assertTasksUpToDate(":example:kaptGenerateStubsKotlin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -292,8 +292,6 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
val kaptTaskProvider: TaskProvider<out KaptTask> = context.createKaptKotlinTask(useWorkerApi = project.isUseWorkerApi())
|
||||
|
||||
kaptGenerateStubsTaskProvider.configure { kaptGenerateStubsTask ->
|
||||
kaptGenerateStubsTask.source(*kaptConfigurations.toTypedArray())
|
||||
|
||||
kaptGenerateStubsTask.dependsOn(*buildDependencies.toTypedArray())
|
||||
kaptGenerateStubsTask.dependsOn(
|
||||
project.provider {
|
||||
|
||||
+5
-2
@@ -76,10 +76,13 @@ abstract class KaptGenerateStubsTask : KotlinCompile(KotlinJvmOptionsImpl()) {
|
||||
@get:Internal
|
||||
lateinit var generatedSourcesDirs: List<File>
|
||||
|
||||
@get:Classpath
|
||||
@get:InputFiles
|
||||
@get:Internal("Not an input, just passed as kapt args. ")
|
||||
abstract val kaptClasspath: ConfigurableFileCollection
|
||||
|
||||
/* Used as input as empty kapt classpath should not trigger stub generation, but a non-empty one should. */
|
||||
@Input
|
||||
fun getIfKaptClasspathIsPresent() = !kaptClasspath.isEmpty
|
||||
|
||||
@get:Classpath
|
||||
@get:InputFiles
|
||||
@Suppress("unused")
|
||||
|
||||
Reference in New Issue
Block a user