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.pluginOptions.addClasspathEntry(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kaptTask.stubsDir = getKaptStubsDir(project, sourceSetName)
|
||||||
|
|
||||||
kaptTask.mapClasspath { kotlinCompile.classpath }
|
kaptTask.mapClasspath { kotlinCompile.classpath }
|
||||||
kaptTask.destinationDir = sourcesOutputDir
|
kaptTask.destinationDir = sourcesOutputDir
|
||||||
kaptTask.classesDir = classesOutputDir
|
kaptTask.classesDir = classesOutputDir
|
||||||
|
|||||||
+11
-4
@@ -39,15 +39,17 @@ open class KaptTask : AbstractCompile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lateinit var classesDir: File
|
lateinit var classesDir: File
|
||||||
|
lateinit var stubsDir: File
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
override fun compile() {
|
override fun compile() {
|
||||||
/** Delete everything inside the [destinationDir] */
|
/** Delete everything inside the [destinationDir] */
|
||||||
destinationDir.deleteRecursively()
|
destinationDir.clearDirectory()
|
||||||
destinationDir.mkdirs()
|
|
||||||
|
|
||||||
classesDir.deleteRecursively()
|
classesDir.clearDirectory()
|
||||||
classesDir.mkdirs()
|
|
||||||
|
// Kapt3 doesn't support incremental compilation so we should delete the existing stubs
|
||||||
|
stubsDir.clearDirectory()
|
||||||
|
|
||||||
val sourceRoots = SourceRoots.ForJvm.create(getSource(), rawSourceRoots)
|
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)
|
val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, environment)
|
||||||
throwGradleExceptionIfError(exitCode)
|
throwGradleExceptionIfError(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun File.clearDirectory() {
|
||||||
|
deleteRecursively()
|
||||||
|
mkdirs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user