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.
This commit is contained in:
committed by
Yan Zhulanow
parent
434fb75eb7
commit
60fa632d02
@@ -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
|
||||
|
||||
@@ -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<File>,
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user