KT-34258: Make sure to clean up stale files even if no Kotlin sources
If running incrementally, even if there aren't any Kotlin sources to compile, there could be stale output files that need to be removed. E.g stub generation must have generated .java files removed if all Kotlin sources are removed. Kotlin compile task will be skipped only if there are no Kotlin sources and task run is non-incremental. Test: KaptIncrementalIT.testRemoveAllKotlinSources
This commit is contained in:
committed by
Yan Zhulanow
parent
a22a60118c
commit
e07b2e30e2
+31
-4
@@ -1,10 +1,8 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.allKotlinFiles
|
||||
import org.jetbrains.kotlin.gradle.util.findFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
open class KaptIncrementalIT : BaseGradleIT() {
|
||||
companion object {
|
||||
@@ -204,6 +202,35 @@ open class KaptIncrementalIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemoveAllKotlinSources() {
|
||||
val project = getProject()
|
||||
val kapt3StubsPath = "build/tmp/kapt3/stubs/main"
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertKapt3FullyExecuted()
|
||||
}
|
||||
|
||||
with(project.projectDir) {
|
||||
resolve("src/main/java").deleteRecursively()
|
||||
resolve("src/main/java/bar").mkdirs()
|
||||
resolve("src/main/java/bar/MyClass.java").writeText(
|
||||
"""
|
||||
package bar;
|
||||
public class MyClass {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
// Make sure all stubs are removed
|
||||
assertEquals(emptyList(), fileInWorkingDir(kapt3StubsPath).walk().filter { it.extension == "java" }.toList())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemoveAnnotations() {
|
||||
val project = getProject()
|
||||
|
||||
+2
-1
@@ -296,7 +296,8 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
|
||||
logger.kotlinDebug { "All kotlin sources: ${allKotlinSources.pathsAsStringRelativeTo(project.rootProject.projectDir)}" }
|
||||
|
||||
if (allKotlinSources.isEmpty()) {
|
||||
if (!inputs.isIncremental && allKotlinSources.isEmpty()) {
|
||||
// Skip running only if non-incremental run. Otherwise, we may need to do some cleanup.
|
||||
logger.kotlinDebug { "No Kotlin files found, skipping Kotlin compiler task" }
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user