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:
Alexey Tsvetkov
2016-04-25 18:01:16 +03:00
parent 853b15ee98
commit f7a665d0d2
3 changed files with 17 additions and 3 deletions
@@ -29,8 +29,6 @@ class AnnotationFileUpdater(private val generatedAnnotationFile: File) {
else {
lastSuccessfullyUpdatedFile.writeText("")
}
lastSuccessfullyUpdatedFile.deleteOnExit()
}
fun updateAnnotations(outdatedClasses: Iterable<JvmClassName>) {
@@ -58,4 +56,8 @@ class AnnotationFileUpdater(private val generatedAnnotationFile: File) {
fun revert() {
lastSuccessfullyUpdatedFile.copyTo(generatedAnnotationFile, overwrite = true)
}
fun dispose() {
lastSuccessfullyUpdatedFile.delete()
}
}
@@ -175,6 +175,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
}
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
private var kaptStubGeneratingMode = false
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
// show kotlin compiler where to look for java source files
@@ -384,7 +385,9 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
targets.forEach { getIncrementalCache(it).let {
it.markOutputClassesDirty(removedAndModified)
it.removeClassfilesBySources(removedAndModified)
if (!kaptStubGeneratingMode) {
it.removeClassfilesBySources(removedAndModified)
}
}}
// can be empty if only removed sources are present
@@ -508,6 +511,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("kaptStubsDir")
if (kaptClassFileStubsDir != null) {
kaptStubGeneratingMode = true
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
}
@@ -531,6 +535,10 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
}
override fun afterCompileHook(args: K2JVMCompilerArguments) {
kaptAnnotationsFileUpdater?.dispose()
if (kaptStubGeneratingMode) return
logger.debug("Copying resulting files to classes")
// Copy kotlin classes to all classes directory
@@ -41,6 +41,7 @@ fun Project.initKapt(
if (kaptExtension.generateStubs) {
kotlinAfterJavaTask = createKotlinAfterJavaTask(javaTask, kotlinTask, kotlinOptions, taskFactory)
mapKotlinTaskProperties(this, kotlinAfterJavaTask)
kotlinTask.logger.kotlinDebug("kapt: Using class file stubs")
@@ -171,6 +172,9 @@ public class AnnotationProcessingManager(
val processorPath = setOf(wrappersDirectory) + aptFiles
setProcessorPath(javaTask, (processorPath + javaTask.classpath).joinToString(File.pathSeparator))
if (aptOutputDir.exists()) {
aptOutputDir.deleteRecursively()
}
addGeneratedSourcesOutputToCompilerArgs(javaTask, aptOutputDir)
appendAnnotationsArguments()