Explicit opt-in switch for Kapt caching.
This commit is contained in:
+9
@@ -34,6 +34,7 @@ import java.io.File
|
|||||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedSourcesDir
|
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedSourcesDir
|
||||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedClassesDir
|
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedClassesDir
|
||||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedKotlinSourcesDir
|
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedKotlinSourcesDir
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.shouldEnableGradleCache
|
||||||
import org.jetbrains.kotlin.gradle.tasks.useBuildCacheIfSupported
|
import org.jetbrains.kotlin.gradle.tasks.useBuildCacheIfSupported
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
@@ -313,6 +314,14 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
|
|
||||||
kaptTask.kaptClasspath = kaptClasspath
|
kaptTask.kaptClasspath = kaptClasspath
|
||||||
|
|
||||||
|
kaptTask.useBuildCache = kaptExtension.useBuildCache
|
||||||
|
|
||||||
|
if (shouldEnableGradleCache()) {
|
||||||
|
val reason = "Caching is disabled by default for kapt because of arbitrary behavior of external " +
|
||||||
|
"annotation processors. You can enable it by adding 'kapt.useBuildCache = true' to the build script."
|
||||||
|
kaptTask.outputs.doNotCacheIf(reason) { !kaptTask.useBuildCache }
|
||||||
|
}
|
||||||
|
|
||||||
buildAndAddOptionsTo(kaptTask.pluginOptions, aptMode = "apt")
|
buildAndAddOptionsTo(kaptTask.pluginOptions, aptMode = "apt")
|
||||||
|
|
||||||
return kaptTask
|
return kaptTask
|
||||||
|
|||||||
+3
@@ -56,6 +56,9 @@ open class KaptTask : ConventionTask(), CompilerArgumentAware<K2JVMCompilerArgum
|
|||||||
val classpath: FileCollection
|
val classpath: FileCollection
|
||||||
get() = kotlinCompileTask.classpath
|
get() = kotlinCompileTask.classpath
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var useBuildCache: Boolean = false
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles @Suppress("unused")
|
@get:Classpath @get:InputFiles @Suppress("unused")
|
||||||
internal val kotlinTaskPluginClasspaths get() = kotlinCompileTask.pluginClasspath
|
internal val kotlinTaskPluginClasspaths get() = kotlinCompileTask.pluginClasspath
|
||||||
|
|
||||||
|
|||||||
+8
@@ -32,12 +32,20 @@ open class KaptExtension {
|
|||||||
|
|
||||||
open var processors: String = ""
|
open var processors: String = ""
|
||||||
|
|
||||||
|
/** Explicit opt-in switch for Kapt caching. Should be used when annotation processors used by this project are
|
||||||
|
* certain NOT to use anything aside from the task inputs in their logic and are guaranteed to produce the same
|
||||||
|
* output on subsequent runs without input changes. */
|
||||||
|
var useBuildCache: Boolean = false
|
||||||
|
|
||||||
private val apOptionsActions =
|
private val apOptionsActions =
|
||||||
mutableListOf<(KaptAnnotationProcessorOptions) -> Unit>()
|
mutableListOf<(KaptAnnotationProcessorOptions) -> Unit>()
|
||||||
|
|
||||||
private val javacOptionsActions =
|
private val javacOptionsActions =
|
||||||
mutableListOf<(KaptJavacOptionsDelegate) -> Unit>()
|
mutableListOf<(KaptJavacOptionsDelegate) -> Unit>()
|
||||||
|
|
||||||
|
private var apOptionsClosure: Closure<*>? = null
|
||||||
|
private var javacOptionsClosure: Closure<*>? = null
|
||||||
|
|
||||||
open fun arguments(closure: Closure<*>) {
|
open fun arguments(closure: Closure<*>) {
|
||||||
apOptionsActions += { apOptions ->
|
apOptionsActions += { apOptions ->
|
||||||
apOptions.execute(closure)
|
apOptions.execute(closure)
|
||||||
|
|||||||
Reference in New Issue
Block a user