Kapt: fix sequential build with kapt when Kotlin source file was modified
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
- Drop line breaks between operator arguments (except '+', "-", "&&" and "||")
|
- Drop line breaks between operator arguments (except '+', "-", "&&" and "||")
|
||||||
- Add non-null assertions on call site for non-null parameters
|
- Add non-null assertions on call site for non-null parameters
|
||||||
|
|
||||||
|
### Tools. Android
|
||||||
|
- Fixed sequential build with kapt and stubs enabled when Kotlin source file was modified and no Java source files were modified
|
||||||
|
|
||||||
### IDE
|
### IDE
|
||||||
- Debugger can distinguish nested inline arguments
|
- Debugger can distinguish nested inline arguments
|
||||||
- Add kotlinClassName() and kotlinFunctionName() macros for use in live templates
|
- Add kotlinClassName() and kotlinFunctionName() macros for use in live templates
|
||||||
|
|||||||
+12
-4
@@ -24,6 +24,7 @@ import org.gradle.api.tasks.compile.JavaCompile
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.util.*
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
fun Project.initKapt(
|
fun Project.initKapt(
|
||||||
@@ -125,6 +126,7 @@ public class AnnotationProcessingManager(
|
|||||||
private val androidVariant: Any? = null) {
|
private val androidVariant: Any? = null) {
|
||||||
|
|
||||||
private val project = task.project
|
private val project = task.project
|
||||||
|
private val random = Random()
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val JAVA_FQNAME_PATTERN = "^([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*$".toRegex()
|
val JAVA_FQNAME_PATTERN = "^([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*$".toRegex()
|
||||||
@@ -184,10 +186,16 @@ public class AnnotationProcessingManager(
|
|||||||
if (!javaHackPackageDir.exists()) javaHackPackageDir.mkdirs()
|
if (!javaHackPackageDir.exists()) javaHackPackageDir.mkdirs()
|
||||||
|
|
||||||
val javaHackClFile = File(javaHackPackageDir, "Cl.java")
|
val javaHackClFile = File(javaHackPackageDir, "Cl.java")
|
||||||
if (!javaHackClFile.exists()) {
|
val previouslyExisted = javaHackClFile.exists()
|
||||||
javaHackClFile.writeText("package __gen.annotation; class Cl { @__gen.KotlinAptAnnotation boolean v; }")
|
val comment = System.currentTimeMillis().toString() + "-" + random.nextInt()
|
||||||
project.logger.kotlinDebug("kapt: Java file stub generated: $javaHackClFile")
|
|
||||||
}
|
javaHackClFile.writeText(
|
||||||
|
"// $comment\n" +
|
||||||
|
"package __gen.annotation;\n" +
|
||||||
|
"class Cl { @__gen.KotlinAptAnnotation boolean v; }")
|
||||||
|
|
||||||
|
project.logger.kotlinDebug("kapt: Java file stub generated: $javaHackClFile " +
|
||||||
|
"(previously existed: $previouslyExisted)")
|
||||||
|
|
||||||
if (!javaTask.source.contains(javaHackClFile)) {
|
if (!javaTask.source.contains(javaHackClFile)) {
|
||||||
javaTask.source(javaAptSourceDir)
|
javaTask.source(javaAptSourceDir)
|
||||||
|
|||||||
+20
-1
@@ -209,6 +209,26 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testKaptStubsIncrementalBuild() {
|
||||||
|
val project = Project("kaptStubs", "1.12")
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
|
||||||
|
// Modify the Kotlin source file somehow
|
||||||
|
val someJavaFile = fileInWorkingDir("src/main/java/test.kt")
|
||||||
|
someJavaFile.appendText(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(":compileKotlin")
|
||||||
|
assertContains(":compileJava")
|
||||||
|
assertNotContains(":compileJava UP-TO-DATE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testKaptArguments() {
|
fun testKaptArguments() {
|
||||||
Project("kaptArguments", "1.12").build("build") {
|
Project("kaptArguments", "1.12").build("build") {
|
||||||
@@ -248,5 +268,4 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user