Add kotlin.incremental project property to gradle
Allows turning on incremental compilation by passing '-Pkotlin.incremental=true' in command line or specifying it in a 'local.properties' file
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
- Show error message when debug info for some local variable is corrupted
|
||||
- [KT-11638](https://youtrack.jetbrains.com/issue/KT-11638) Fixed hashCode() implementation in "Generate equals/hashCode" action
|
||||
|
||||
### Tools.Gradle
|
||||
- Added project property 'kotlin.incremental'
|
||||
|
||||
## 1.0.1-2
|
||||
|
||||
### Compiler
|
||||
|
||||
+2
@@ -106,6 +106,7 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
|
||||
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
||||
kotlinTask.description = taskDescription
|
||||
kotlinTask.source(kotlinDirSet)
|
||||
mapKotlinTaskProperties(project, kotlinTask)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,6 +377,7 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
||||
|
||||
val kotlinTaskName = "compile${variantDataName.capitalize()}Kotlin"
|
||||
val kotlinTask = tasksProvider.createKotlinJVMTask(project, kotlinTaskName)
|
||||
mapKotlinTaskProperties(project, kotlinTask)
|
||||
|
||||
kotlinTask.extensions.extraProperties.set("defaultModuleName", "${project.name}-$kotlinTaskName")
|
||||
if (kotlinOptions != null) {
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
|
||||
fun mapKotlinTaskProperties(project: Project, task: AbstractCompile) {
|
||||
for (mapping in propertyMappings) {
|
||||
mapping.apply(project, task)
|
||||
}
|
||||
}
|
||||
|
||||
private val propertyMappings = listOf(
|
||||
KotlinPropertyMapping("kotlin.incremental", "experimentalIncremental", String::toBoolean)
|
||||
)
|
||||
|
||||
private class KotlinPropertyMapping<T>(
|
||||
private val projectPropName: String,
|
||||
private val taskPropName: String,
|
||||
private val transform: (String) -> T
|
||||
) {
|
||||
fun apply(project: Project, task: AbstractCompile) {
|
||||
if (!project.hasProperty(projectPropName)) return
|
||||
|
||||
val value = project.property(projectPropName) as? String ?: return
|
||||
val transformedValue = transform(value) ?: return
|
||||
task.setProperty(taskPropName, transformedValue)
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -70,6 +70,7 @@ abstract class BaseGradleIT {
|
||||
data class BuildOptions(
|
||||
val withDaemon: Boolean = false,
|
||||
val daemonOptionSupported: Boolean = true,
|
||||
val incremental: Boolean? = null,
|
||||
/**
|
||||
* @see [ThreadTracker]
|
||||
*/
|
||||
@@ -201,8 +202,8 @@ abstract class BaseGradleIT {
|
||||
private fun Project.createBuildCommand(params: Array<out String>, options: BuildOptions): List<String> =
|
||||
createGradleCommand(createGradleTailParameters(options, params))
|
||||
|
||||
protected fun Project.createGradleTailParameters(options: BuildOptions, tasks: Array<out String> = arrayOf()): List<String> =
|
||||
tasks.toMutableList().apply {
|
||||
private fun Project.createGradleTailParameters(options: BuildOptions, params: Array<out String> = arrayOf()): List<String> =
|
||||
params.toMutableList().apply {
|
||||
add("--stacktrace")
|
||||
add("--${minLogLevel.name.toLowerCase()}")
|
||||
if (options.daemonOptionSupported) {
|
||||
@@ -213,6 +214,8 @@ abstract class BaseGradleIT {
|
||||
if (options.assertThreadLeaks) {
|
||||
add("-P${ThreadTracker.ASSERT_THREAD_LEAKS_PROPERTY}=true")
|
||||
}
|
||||
options.incremental?.let { add("-Pkotlin.incremental=$it") }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -127,13 +127,14 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
|
||||
@Test
|
||||
fun testSimpleMultiprojectIncremental() {
|
||||
|
||||
fun Project.modify(body: Project.() -> Unit): Project {
|
||||
this.body()
|
||||
return this
|
||||
}
|
||||
|
||||
Project("multiprojectWithDependency", "1.6").build("-PincrementalOption=true", "assemble") {
|
||||
val incremental = defaultBuildOptions().copy(incremental = true)
|
||||
|
||||
Project("multiprojectWithDependency", "1.6").build("assemble", options = incremental) {
|
||||
assertSuccessful()
|
||||
assertReportExists("projA")
|
||||
assertContains(":projA:compileKotlin")
|
||||
@@ -148,7 +149,7 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
assertTrue { oldSrc.exists() }
|
||||
assertTrue { newSrc.exists() }
|
||||
newSrc.copyTo(oldSrc, overwrite = true)
|
||||
}.build("-PincrementalOption=true", "assemble") {
|
||||
}.build("assemble", options = incremental) {
|
||||
assertSuccessful()
|
||||
assertReportExists("projA")
|
||||
assertContains(":projA:compileKotlin")
|
||||
|
||||
+2
-2
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
@@ -24,7 +23,8 @@ class KotlinGradlePluginJpsParametrizedCLIOnly : BaseIncrementalGradleIT() {
|
||||
JpsTestProject(jpsResourcesPath, relativePath).performAndAssertBuildStages(weakTesting = true)
|
||||
}
|
||||
|
||||
override fun defaultBuildOptions(): BuildOptions = BuildOptions(withDaemon = true)
|
||||
override fun defaultBuildOptions(): BuildOptions =
|
||||
BuildOptions(withDaemon = true, incremental = true)
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
-4
@@ -22,10 +22,6 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
experimentalIncremental = true
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
|
||||
-4
@@ -7,7 +7,3 @@ repositories {
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
experimentalIncremental = incrementalOption
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -9,8 +9,4 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile project(':projA')
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
experimentalIncremental = incrementalOption
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user