From 60fa632d0261eb278bec49e5deb6779788bcd807 Mon Sep 17 00:00:00 2001 From: Ivan Gavrilovic Date: Tue, 27 Aug 2019 13:11:35 +0200 Subject: [PATCH] KT-33515: Remove Kotlin sources generated by KAPT When KAPT is unable to run incrementally make sure to clean directory that contains generated Kotlin sources. This location is specified using '-Akapt.kotlin.generated' option. --- .../src/org/jetbrains/kotlin/kapt3/base/KaptContext.kt | 3 +++ .../src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt | 7 +++++++ .../src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt | 9 +-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptContext.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptContext.kt index 64bb524ee85..4a40c2a4741 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptContext.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptContext.kt @@ -73,6 +73,9 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge } deleteAndCreate(options.sourcesOutputDir) deleteAndCreate(options.classesOutputDir) + options.getKotlinGeneratedSourcesDirectory()?.let { + deleteAndCreate(it) + } } } else { sourcesToReprocess = SourcesToReprocess.FullRebuild diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt index a368e2d1fd6..a3fb4813f80 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.kapt3.base.incremental.SourcesToReprocess import java.io.File import java.nio.file.Files +private const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated" + class KaptOptions( val projectBaseDir: File?, val compileClasspath: List, @@ -80,6 +82,11 @@ class KaptOptions( ) } } + + fun getKotlinGeneratedSourcesDirectory(): File? { + val value = processingOptions[KAPT_KOTLIN_GENERATED_OPTION_NAME] ?: return null + return File(value).takeIf { it.exists() } + } } interface KaptFlags { diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt index 78fd27ed63c..41273dd0ede 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt @@ -66,8 +66,6 @@ import java.io.Writer import java.net.URLClassLoader import javax.annotation.processing.Processor -private const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated" - class ClasspathBasedKapt3Extension( options: KaptOptions, logger: MessageCollectorBackedKaptLogger, @@ -209,17 +207,12 @@ abstract class AbstractKapt3Extension( bindingTrace.bindingContext, module, listOf(options.sourcesOutputDir), - listOfNotNull(options.sourcesOutputDir, getKotlinGeneratedSourcesDirectory()), + listOfNotNull(options.sourcesOutputDir, options.getKotlinGeneratedSourcesDirectory()), addToEnvironment = true ) } } - private fun getKotlinGeneratedSourcesDirectory(): File? { - val value = options.processingOptions[KAPT_KOTLIN_GENERATED_OPTION_NAME] ?: return null - return File(value).takeIf { it.exists() } - } - private fun runAnnotationProcessing(kaptContext: KaptContext, processors: LoadedProcessors) { if (!options.mode.runAnnotationProcessing) return