Fix incremental compilation with kapt generating stubs
Changes: * map incremental property to compile kotlin after java task * when generating stubs compile kotlin task should not remove or copy classfiles
This commit is contained in:
+4
-2
@@ -29,8 +29,6 @@ class AnnotationFileUpdater(private val generatedAnnotationFile: File) {
|
|||||||
else {
|
else {
|
||||||
lastSuccessfullyUpdatedFile.writeText("")
|
lastSuccessfullyUpdatedFile.writeText("")
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSuccessfullyUpdatedFile.deleteOnExit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAnnotations(outdatedClasses: Iterable<JvmClassName>) {
|
fun updateAnnotations(outdatedClasses: Iterable<JvmClassName>) {
|
||||||
@@ -58,4 +56,8 @@ class AnnotationFileUpdater(private val generatedAnnotationFile: File) {
|
|||||||
fun revert() {
|
fun revert() {
|
||||||
lastSuccessfullyUpdatedFile.copyTo(generatedAnnotationFile, overwrite = true)
|
lastSuccessfullyUpdatedFile.copyTo(generatedAnnotationFile, overwrite = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dispose() {
|
||||||
|
lastSuccessfullyUpdatedFile.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+9
-1
@@ -175,6 +175,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
|
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
|
||||||
|
private var kaptStubGeneratingMode = false
|
||||||
|
|
||||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||||
// show kotlin compiler where to look for java source files
|
// show kotlin compiler where to look for java source files
|
||||||
@@ -384,7 +385,9 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
targets.forEach { getIncrementalCache(it).let {
|
targets.forEach { getIncrementalCache(it).let {
|
||||||
it.markOutputClassesDirty(removedAndModified)
|
it.markOutputClassesDirty(removedAndModified)
|
||||||
it.removeClassfilesBySources(removedAndModified)
|
if (!kaptStubGeneratingMode) {
|
||||||
|
it.removeClassfilesBySources(removedAndModified)
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// can be empty if only removed sources are present
|
// can be empty if only removed sources are present
|
||||||
@@ -508,6 +511,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("kaptStubsDir")
|
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("kaptStubsDir")
|
||||||
if (kaptClassFileStubsDir != null) {
|
if (kaptClassFileStubsDir != null) {
|
||||||
|
kaptStubGeneratingMode = true
|
||||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
|
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,6 +535,10 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
||||||
|
kaptAnnotationsFileUpdater?.dispose()
|
||||||
|
|
||||||
|
if (kaptStubGeneratingMode) return
|
||||||
|
|
||||||
logger.debug("Copying resulting files to classes")
|
logger.debug("Copying resulting files to classes")
|
||||||
|
|
||||||
// Copy kotlin classes to all classes directory
|
// Copy kotlin classes to all classes directory
|
||||||
|
|||||||
+4
@@ -41,6 +41,7 @@ fun Project.initKapt(
|
|||||||
|
|
||||||
if (kaptExtension.generateStubs) {
|
if (kaptExtension.generateStubs) {
|
||||||
kotlinAfterJavaTask = createKotlinAfterJavaTask(javaTask, kotlinTask, kotlinOptions, taskFactory)
|
kotlinAfterJavaTask = createKotlinAfterJavaTask(javaTask, kotlinTask, kotlinOptions, taskFactory)
|
||||||
|
mapKotlinTaskProperties(this, kotlinAfterJavaTask)
|
||||||
|
|
||||||
kotlinTask.logger.kotlinDebug("kapt: Using class file stubs")
|
kotlinTask.logger.kotlinDebug("kapt: Using class file stubs")
|
||||||
|
|
||||||
@@ -171,6 +172,9 @@ public class AnnotationProcessingManager(
|
|||||||
val processorPath = setOf(wrappersDirectory) + aptFiles
|
val processorPath = setOf(wrappersDirectory) + aptFiles
|
||||||
setProcessorPath(javaTask, (processorPath + javaTask.classpath).joinToString(File.pathSeparator))
|
setProcessorPath(javaTask, (processorPath + javaTask.classpath).joinToString(File.pathSeparator))
|
||||||
|
|
||||||
|
if (aptOutputDir.exists()) {
|
||||||
|
aptOutputDir.deleteRecursively()
|
||||||
|
}
|
||||||
addGeneratedSourcesOutputToCompilerArgs(javaTask, aptOutputDir)
|
addGeneratedSourcesOutputToCompilerArgs(javaTask, aptOutputDir)
|
||||||
|
|
||||||
appendAnnotationsArguments()
|
appendAnnotationsArguments()
|
||||||
|
|||||||
Reference in New Issue
Block a user