From baeeec8abc5f79eace50dc9f70aa7961325803f2 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Tue, 16 May 2023 12:13:43 +0300 Subject: [PATCH] Delay resolving dependencies until configuration phase is over (#3170) Resolves #3169 --- .../kotlin/org/jetbrains/compose/ComposePlugin.kt | 4 ++-- .../internal/checkExperimentalTargets.kt | 15 ++++++++++++--- .../test/tests/integration/GradlePluginTest.kt | 11 +++++++++++ .../jetbrains/compose/test/utils/TestProject.kt | 12 +++++++++--- .../test-projects/misc/skikoWasm/build.gradle | 7 +++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt index 3819896ab0..87b13b4e66 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt @@ -22,7 +22,7 @@ import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.internal.configureDesktop import org.jetbrains.compose.desktop.preview.internal.initializePreview import org.jetbrains.compose.experimental.dsl.ExperimentalExtension -import org.jetbrains.compose.experimental.internal.checkExperimentalTargetsWithSkikoIsEnabled +import org.jetbrains.compose.experimental.internal.configureExperimentalTargetsFlagsCheck import org.jetbrains.compose.experimental.internal.configureExperimental import org.jetbrains.compose.internal.utils.currentTarget import org.jetbrains.compose.web.WebExtension @@ -53,7 +53,7 @@ class ComposePlugin : Plugin { project.afterEvaluate { configureDesktop(project, desktopExtension) project.configureExperimental(composeExtension, experimentalExtension) - project.checkExperimentalTargetsWithSkikoIsEnabled() + project.configureExperimentalTargetsFlagsCheck() project.tasks.withType(KotlinCompile::class.java).configureEach { it.kotlinOptions.apply { diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt index 0523517dd4..db2ceec3f8 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt @@ -6,9 +6,18 @@ package org.jetbrains.compose.experimental.internal import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID +import org.jetbrains.compose.internal.mppExt import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +internal fun Project.configureExperimentalTargetsFlagsCheck() { + plugins.withId(KOTLIN_MPP_PLUGIN_ID) { + gradle.taskGraph.whenReady { + checkExperimentalTargetsWithSkikoIsEnabled() + } + } +} + private const val SKIKO_ARTIFACT_PREFIX = "org.jetbrains.skiko:skiko" private class TargetType( @@ -29,8 +38,8 @@ private sealed interface CheckResult { class Fail(val target: TargetType) : CheckResult } -internal fun Project.checkExperimentalTargetsWithSkikoIsEnabled() = afterEvaluate { - val mppExt = project.extensions.findByType(KotlinMultiplatformExtension::class.java) ?: return@afterEvaluate +private fun Project.checkExperimentalTargetsWithSkikoIsEnabled() { + val mppExt = project.mppExt val failedResults = mppExt.targets.map { checkTarget(it) } .filterIsInstance() .distinctBy { it.target } diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt index 584cf27c0e..ab4c765ef6 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt @@ -28,6 +28,17 @@ class GradlePluginTest : GradlePluginTestBase() { testEnvironment = defaultTestEnvironment.copy(useGradleConfigurationCache = false) ) ) { + fun jsCanvasEnabled(value: Boolean) { + modifyGradleProperties { put("org.jetbrains.compose.experimental.jscanvas.enabled", value.toString()) } + + } + + jsCanvasEnabled(false) + gradleFailure(":build").checks { + check.logContains("ERROR: Compose targets '[jscanvas]' are experimental and may have bugs!") + } + + jsCanvasEnabled(true) gradle(":build").checks { check.taskSuccessful(":unpackSkikoWasmRuntimeJs") check.taskSuccessful(":compileKotlinJs") diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt index 5ff6df7829..3b4be8f071 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt @@ -76,7 +76,13 @@ class TestProject( } } - internal fun gradle(vararg args: String): BuildResult { + internal fun gradle(vararg args: String): BuildResult = + withGradleRunner(args) { build() } + + internal fun gradleFailure(vararg args: String): BuildResult = + withGradleRunner(args) { buildAndFail() } + + private inline fun withGradleRunner(args: Array, runnerFn: GradleRunner.() -> BuildResult): BuildResult { if (testEnvironment.useGradleConfigurationCache) { if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) { // Gradle 7.* does not use the configuration cache in the same build. @@ -84,11 +90,11 @@ class TestProject( // but does not, use the serialized task graph. // So in order to test the cache, we need to perform dry-run before the actual run. // This should be fixed in https://github.com/gradle/gradle/issues/21985 (which is planned for 8.0 RC 1) - gradleRunner(args.withDryRun()).build() + gradleRunner(args.withDryRun()).runnerFn() } } - return gradleRunner(args).build() + return gradleRunner(args).runnerFn() } private fun Array.withDryRun(): Array { diff --git a/gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle b/gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle index 236b7e4062..c726f9fc5c 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle +++ b/gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle @@ -28,4 +28,11 @@ kotlin { compose.experimental { web.application {} +} + +// test for https://github.com/JetBrains/compose-multiplatform/issues/3169 +afterEvaluate { + afterEvaluate { + dependencies.add(kotlin.targets.js.compilations.main.compileDependencyConfigurationName, "org.jetbrains.kotlin:kotlin-stdlib") + } } \ No newline at end of file