Kapt: support incremental compilation in Gradle (KT-13500)
Kapt will process sources on each step of incremental compilation. (cherry picked from commit 4cb2127)
This commit is contained in:
committed by
Yan Zhulanow
parent
743be477ec
commit
32d77e5226
+12
-4
@@ -78,19 +78,24 @@ class Kapt2KotlinGradleSubplugin : KotlinGradleSubplugin {
|
||||
kaptClasspath.addAll(kapt2Configuration.resolve())
|
||||
}
|
||||
}
|
||||
|
||||
val generatedFilesDir = if (variantData != null) {
|
||||
|
||||
val sourceSetName = if (variantData != null) {
|
||||
for (provider in (variantData as BaseVariantData<*>).sourceProviders) {
|
||||
handleSourceSet((provider as AndroidSourceSet).name)
|
||||
}
|
||||
|
||||
getKaptGeneratedDir(project, variantData.name).apply { variantData.addJavaSourceFoldersToModel(this) }
|
||||
variantData.name
|
||||
}
|
||||
else {
|
||||
if (javaSourceSet == null) error("Java source set should not be null")
|
||||
|
||||
handleSourceSet(javaSourceSet.name)
|
||||
getKaptGeneratedDir(project, javaSourceSet.name)
|
||||
javaSourceSet.name
|
||||
}
|
||||
|
||||
val generatedFilesDir = getKaptGeneratedDir(project, sourceSetName)
|
||||
if (variantData != null) {
|
||||
(variantData as BaseVariantData<*>).addJavaSourceFoldersToModel(generatedFilesDir)
|
||||
}
|
||||
|
||||
// Skip annotation processing in kotlinc if no kapt dependencies were provided
|
||||
@@ -117,6 +122,9 @@ class Kapt2KotlinGradleSubplugin : KotlinGradleSubplugin {
|
||||
pluginOptions += SubpluginOption("verbose", "true")
|
||||
}
|
||||
|
||||
val incrementalCompilationDataFile = File(project.buildDir, "tmp/kapt2/$sourceSetName/incrementalData.txt")
|
||||
pluginOptions += SubpluginOption("incrementalData", incrementalCompilationDataFile.absolutePath)
|
||||
|
||||
return pluginOptions
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
@@ -63,6 +64,31 @@ class Kapt2IT: BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleWithIC() {
|
||||
val options = defaultBuildOptions().copy(incremental = true)
|
||||
val project = Project("simple", GRADLE_VERSION, directoryPrefix = "kapt2")
|
||||
|
||||
project.build("build", options = options) {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
assertContains(":compileKotlin")
|
||||
assertContains(":compileJava")
|
||||
}
|
||||
|
||||
val files = listOf("InternalDummy.kt", "test.kt")
|
||||
kotlin.repeat(2) { i ->
|
||||
project.projectDir.getFileByName(files[i]).appendText(" ")
|
||||
|
||||
project.build("build", options = options) {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
assertContains(":compileKotlin")
|
||||
assertContains(":compileJava")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInheritedAnnotations() {
|
||||
Project("inheritedAnnotations", GRADLE_VERSION, directoryPrefix = "kapt2").build("build") {
|
||||
|
||||
Reference in New Issue
Block a user