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 7da98f98d0..e799b48904 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() if (androidExtension.useAndroidX) { project.logger.warn("useAndroidX is an experimental feature at the moment!") 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 aa04f3658c..aece82e402 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 @@ -21,6 +21,17 @@ import org.junit.jupiter.api.Test class GradlePluginTest : GradlePluginTestBase() { @Test fun skikoWasm() = with(testProject(TestProjects.skikoWasm)) { + 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 f1d5e4f794..783d9e8852 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 @@ -75,7 +75,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 (TestProperties.gradleConfigurationCache) { if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) { // Gradle 7.* does not use the configuration cache in the same build. @@ -83,11 +89,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