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.sourcesOutputDir)
|
||||||
deleteAndCreate(options.classesOutputDir)
|
deleteAndCreate(options.classesOutputDir)
|
||||||
|
options.getKotlinGeneratedSourcesDirectory()?.let {
|
||||||
|
deleteAndCreate(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sourcesToReprocess = SourcesToReprocess.FullRebuild
|
sourcesToReprocess = SourcesToReprocess.FullRebuild
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.kapt3.base.incremental.SourcesToReprocess
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
private const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated"
|
||||||
|
|
||||||
class KaptOptions(
|
class KaptOptions(
|
||||||
val projectBaseDir: File?,
|
val projectBaseDir: File?,
|
||||||
val compileClasspath: List<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 {
|
interface KaptFlags {
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ import java.io.Writer
|
|||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import javax.annotation.processing.Processor
|
import javax.annotation.processing.Processor
|
||||||
|
|
||||||
private const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated"
|
|
||||||
|
|
||||||
class ClasspathBasedKapt3Extension(
|
class ClasspathBasedKapt3Extension(
|
||||||
options: KaptOptions,
|
options: KaptOptions,
|
||||||
logger: MessageCollectorBackedKaptLogger,
|
logger: MessageCollectorBackedKaptLogger,
|
||||||
@@ -209,17 +207,12 @@ abstract class AbstractKapt3Extension(
|
|||||||
bindingTrace.bindingContext,
|
bindingTrace.bindingContext,
|
||||||
module,
|
module,
|
||||||
listOf(options.sourcesOutputDir),
|
listOf(options.sourcesOutputDir),
|
||||||
listOfNotNull(options.sourcesOutputDir, getKotlinGeneratedSourcesDirectory()),
|
listOfNotNull(options.sourcesOutputDir, options.getKotlinGeneratedSourcesDirectory()),
|
||||||
addToEnvironment = true
|
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) {
|
private fun runAnnotationProcessing(kaptContext: KaptContext, processors: LoadedProcessors) {
|
||||||
if (!options.mode.runAnnotationProcessing) return
|
if (!options.mode.runAnnotationProcessing) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user