Kapt3: Fix compatibility with IC (KT-16753)
Kapt does not support incremental compilation for stubs so we should delete source stubs before running annotation processing.
This commit is contained in:
+2
@@ -240,6 +240,8 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
kaptTask.pluginOptions.addClasspathEntry(it)
|
||||
}
|
||||
|
||||
kaptTask.stubsDir = getKaptStubsDir(project, sourceSetName)
|
||||
|
||||
kaptTask.mapClasspath { kotlinCompile.classpath }
|
||||
kaptTask.destinationDir = sourcesOutputDir
|
||||
kaptTask.classesDir = classesOutputDir
|
||||
|
||||
+11
-4
@@ -39,15 +39,17 @@ open class KaptTask : AbstractCompile() {
|
||||
}
|
||||
|
||||
lateinit var classesDir: File
|
||||
lateinit var stubsDir: File
|
||||
|
||||
@TaskAction
|
||||
override fun compile() {
|
||||
/** Delete everything inside the [destinationDir] */
|
||||
destinationDir.deleteRecursively()
|
||||
destinationDir.mkdirs()
|
||||
destinationDir.clearDirectory()
|
||||
|
||||
classesDir.deleteRecursively()
|
||||
classesDir.mkdirs()
|
||||
classesDir.clearDirectory()
|
||||
|
||||
// Kapt3 doesn't support incremental compilation so we should delete the existing stubs
|
||||
stubsDir.clearDirectory()
|
||||
|
||||
val sourceRoots = SourceRoots.ForJvm.create(getSource(), rawSourceRoots)
|
||||
|
||||
@@ -69,4 +71,9 @@ open class KaptTask : AbstractCompile() {
|
||||
val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, environment)
|
||||
throwGradleExceptionIfError(exitCode)
|
||||
}
|
||||
|
||||
private fun File.clearDirectory() {
|
||||
deleteRecursively()
|
||||
mkdirs()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user