Fix KT-36804 by eagerly instantiating the Kotlin/Native tasks

This commit partially reverts 970ee4539b.

The Kotlin/Native klib compilation task configuration logic involved
adding dependencies for the compiler plugin artifacts. However, the
compiler plugins classpath, shared across all of the K/N tasks, was
tracked as the tasks' input. This made the following scenario possible:

1. Configuration of some of the Kotlin/Native tasks is avoided at the
   evaluation phase;

2. During task graph construction, one of the tasks are evaluated, and
   to determine their dependencies, Gradle resolves their inputs,
   including the compiler plugins classpath mentioned above;

3. Another K/N task is evaluated afterwards, and the configuration logic
   attempts to add a dependency into the compiler plugin classpath
   configuration, which has already been resolved in (2).
   The build fails.

Fix this by cancelling task configuration avoidance for the K/N tasks.

Issue #KT-36804 Fixed
This commit is contained in:
Sergey Igushkin
2020-02-18 15:59:28 +03:00
parent 582ce1199f
commit faa95bfc33
2 changed files with 6 additions and 6 deletions
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.sources.*
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
import org.jetbrains.kotlin.gradle.tasks.locateTask
import org.jetbrains.kotlin.gradle.tasks.registerTask
@@ -127,7 +127,7 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
override val kotlinTask: TaskProvider<out KotlinNativeCompile> =
with(nativeTargetConfigurator) {
project.createKlibCompilationTask(kotlinCompilation)
}
}.thisTaskProvider
override fun run() = Unit
}
@@ -149,11 +149,11 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
}
}
internal fun Project.createKlibCompilationTask(compilation: AbstractKotlinNativeCompilation): TaskProvider<out KotlinNativeCompile> {
val compileTask = project.registerTask<KotlinNativeCompile>(
internal fun Project.createKlibCompilationTask(compilation: AbstractKotlinNativeCompilation): KotlinNativeCompile {
val compileTask = project.tasks.create(
compilation.compileKotlinTaskName,
KotlinNativeCompile::class.java
) { task ->
).also { task ->
task.compilation = compilation
task.group = BasePlugin.BUILD_GROUP
task.description = "Compiles a klibrary from the '${compilation.name}' " +
@@ -178,7 +178,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).apply {
dependsOn(compileTask)
}
createRegularKlibArtifact(compilation, compileTask.get() /*TODO don't instantiate the task eagerly*/)
createRegularKlibArtifact(compilation, compileTask)
}
return compileTask