Delete output when unable to run KAPT incrementally

When comparing previous and current classpath snapshots, and it is not
possible to compute the types that changed, make sure to delete the outputs
before invoking KAPT.

Test: KaptIncrementalWithAggregatingApt.testIncompatibleClasspathChanges
This commit is contained in:
Ivan Gavrilovic
2019-08-07 11:36:43 +01:00
committed by Yan Zhulanow
parent e4f9314f94
commit 2412b5f992
3 changed files with 69 additions and 28 deletions
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.gradle.util.modify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import kotlin.test.assertFalse
class KaptIncrementalWithAggregatingApt : KaptIncrementalIT() {
@@ -136,4 +137,37 @@ class KaptIncrementalWithAggregatingApt : KaptIncrementalIT() {
assertTrue(getProcessedSources(output).isEmpty())
}
}
@Test
fun testIncompatibleClasspathChanges() {
val project = getProject()
project.projectFile("useB.kt").modify { current ->
current + """
@example.ExampleAnnotation
fun addedFunctionB() = ""
""".trimIndent()
}
project.build("clean", "build") {
assertSuccessful()
}
project.projectFile("useB.kt").modify { current ->
current.replace("fun addedFunctionB", "fun renamedFunctionB")
}
project.gradleBuildScript().appendText("""
dependencies {
compile 'com.google.guava:guava:12.0'
}
""".trimIndent())
project.build("build") {
assertSuccessful()
assertFalse(
fileInWorkingDir("build/generated/source/kapt/main/bar/AddedFunctionBGenerated.java").exists(),
"Generated file should be deleted for renamed function when classpath changes."
)
}
}
}