Make the tasks cacheable, add logic that decides whether to cache them
This commit is contained in:
+13
-2
@@ -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.getKaptGeneratedClassesDir
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedKotlinSourcesDir
|
||||
import org.jetbrains.kotlin.gradle.tasks.useBuildCacheIfSupported
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.util.*
|
||||
@@ -280,7 +281,12 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
}
|
||||
|
||||
private fun Kapt3SubpluginContext.createKaptKotlinTask(): KaptTask {
|
||||
val kaptTask = project.tasks.create(getKaptTaskName("kapt"), KaptTask::class.java)
|
||||
val kaptTask = project.tasks.create(
|
||||
getKaptTaskName("kapt"),
|
||||
KaptTask::class.java)
|
||||
|
||||
kaptTask.useBuildCacheIfSupported()
|
||||
|
||||
kaptTask.kotlinCompileTask = kotlinCompile
|
||||
|
||||
kaptClasspathArtifacts.forEach { kaptTask.pluginOptions.addClasspathEntry(it) }
|
||||
@@ -312,7 +318,12 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
}
|
||||
|
||||
private fun Kapt3SubpluginContext.createKaptGenerateStubsTask(): KaptGenerateStubsTask {
|
||||
val kaptTask = project.tasks.create(getKaptTaskName("kaptGenerateStubs"), KaptGenerateStubsTask::class.java)
|
||||
val kaptTask = project.tasks.create(
|
||||
getKaptTaskName("kaptGenerateStubs"),
|
||||
KaptGenerateStubsTask::class.java)
|
||||
|
||||
kaptTask.useBuildCacheIfSupported()
|
||||
|
||||
kaptTask.sourceSetName = sourceSetName
|
||||
kaptTask.kotlinCompileTask = kotlinCompile
|
||||
kotlinToKaptGenerateStubsTasksMap[kotlinCompile] = kaptTask
|
||||
|
||||
+1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.incremental.destinationAsFile
|
||||
import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo
|
||||
import java.io.File
|
||||
|
||||
@CacheableTask
|
||||
open class KaptGenerateStubsTask : KotlinCompile() {
|
||||
override val sourceRootsContainer = FilteringSourceRootsContainer(emptyList(), { isSourceRootAllowed(it) })
|
||||
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import java.io.File
|
||||
|
||||
@CacheableTask
|
||||
open class KaptTask : ConventionTask(), CompilerArgumentAware<K2JVMCompilerArguments> {
|
||||
|
||||
@get:Internal
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import org.gradle.api.plugins.JavaPluginConvention
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.tasks.useBuildCacheIfSupported
|
||||
import java.io.File
|
||||
|
||||
class KotlinJsDcePlugin : Plugin<Project> {
|
||||
@@ -45,6 +46,8 @@ class KotlinJsDcePlugin : Plugin<Project> {
|
||||
project.tasks.findByName("build")!!.dependsOn(it)
|
||||
}
|
||||
|
||||
dceTask.useBuildCacheIfSupported()
|
||||
|
||||
project.afterEvaluate {
|
||||
val outputDir = File(File(project.buildDir, DEFAULT_OUT_DIR), sourceSet.name)
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
private val gradleVersion = GradleVersion.current()
|
||||
|
||||
internal fun shouldEnableGradleCache(): Boolean =
|
||||
gradleVersion >= GradleVersion.version("4.3")
|
||||
|
||||
internal fun <T : Task> T.useBuildCacheIfSupported() {
|
||||
when {
|
||||
gradleVersion >= GradleVersion.version("3.4") ->
|
||||
outputs.cacheIf("Gradle version is at least 4.3") { shouldEnableGradleCache() }
|
||||
|
||||
// There was no 'cacheIf' method accepting a reason string before 3.4:
|
||||
gradleVersion >= GradleVersion.version("3.0") -> outputs.cacheIf { false }
|
||||
|
||||
// Before 3.0, there was no build cache at all, no need to restrict anything
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
+2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.gradle.dsl.fillDefaultValues
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import java.io.File
|
||||
|
||||
@CacheableTask
|
||||
internal open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompilerArguments>(), KotlinCommonCompile {
|
||||
|
||||
private val kotlinOptionsImpl = KotlinMultiplatformCommonOptionsImpl()
|
||||
|
||||
+2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptionsImpl
|
||||
import java.io.File
|
||||
|
||||
@CacheableTask
|
||||
open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJsDce {
|
||||
|
||||
override fun createCompilerArgs(): K2JSDceArguments = K2JSDceArguments()
|
||||
|
||||
+2
@@ -240,6 +240,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
}
|
||||
}
|
||||
|
||||
@CacheableTask
|
||||
open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), KotlinJvmCompile {
|
||||
@get:Internal
|
||||
internal var parentKotlinOptionsImpl: KotlinJvmOptionsImpl? = null
|
||||
@@ -430,6 +431,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
}
|
||||
}
|
||||
|
||||
@CacheableTask
|
||||
open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(), KotlinJsCompile {
|
||||
private val kotlinOptionsImpl = KotlinJsOptionsImpl()
|
||||
|
||||
|
||||
+3
@@ -24,16 +24,19 @@ import org.jetbrains.kotlin.gradle.plugin.mapKotlinTaskProperties
|
||||
internal open class KotlinTasksProvider {
|
||||
fun createKotlinJVMTask(project: Project, name: String, sourceSetName: String): KotlinCompile =
|
||||
project.tasks.create(name, KotlinCompile::class.java).apply {
|
||||
useBuildCacheIfSupported()
|
||||
configure(project, sourceSetName)
|
||||
}
|
||||
|
||||
fun createKotlinJSTask(project: Project, name: String, sourceSetName: String): Kotlin2JsCompile =
|
||||
project.tasks.create(name, Kotlin2JsCompile::class.java).apply {
|
||||
useBuildCacheIfSupported()
|
||||
configure(project, sourceSetName)
|
||||
}
|
||||
|
||||
fun createKotlinCommonTask(project: Project, name: String, sourceSetName: String): KotlinCompileCommon =
|
||||
project.tasks.create(name, KotlinCompileCommon::class.java).apply {
|
||||
useBuildCacheIfSupported()
|
||||
configure(project, sourceSetName)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user