Browse Source

Delay resolving dependencies until configuration phase is over (#3170)

Resolves #3169
# Conflicts:
#	gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
#	gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
release/1.4.2
Alexey Tsvetkov 2 years ago committed by Igor Demin
parent
commit
aceac17d54
  1. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  2. 15
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt
  3. 11
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  4. 12
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
  5. 7
      gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle

4
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.application.internal.configureDesktop
import org.jetbrains.compose.desktop.preview.internal.initializePreview import org.jetbrains.compose.desktop.preview.internal.initializePreview
import org.jetbrains.compose.experimental.dsl.ExperimentalExtension 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.experimental.internal.configureExperimental
import org.jetbrains.compose.internal.utils.currentTarget import org.jetbrains.compose.internal.utils.currentTarget
import org.jetbrains.compose.web.WebExtension import org.jetbrains.compose.web.WebExtension
@ -53,7 +53,7 @@ class ComposePlugin : Plugin<Project> {
project.afterEvaluate { project.afterEvaluate {
configureDesktop(project, desktopExtension) configureDesktop(project, desktopExtension)
project.configureExperimental(composeExtension, experimentalExtension) project.configureExperimental(composeExtension, experimentalExtension)
project.checkExperimentalTargetsWithSkikoIsEnabled() project.configureExperimentalTargetsFlagsCheck()
if (androidExtension.useAndroidX) { if (androidExtension.useAndroidX) {
project.logger.warn("useAndroidX is an experimental feature at the moment!") project.logger.warn("useAndroidX is an experimental feature at the moment!")

15
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt

@ -6,9 +6,18 @@
package org.jetbrains.compose.experimental.internal package org.jetbrains.compose.experimental.internal
import org.gradle.api.Project 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 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 const val SKIKO_ARTIFACT_PREFIX = "org.jetbrains.skiko:skiko"
private class TargetType( private class TargetType(
@ -29,8 +38,8 @@ private sealed interface CheckResult {
class Fail(val target: TargetType) : CheckResult class Fail(val target: TargetType) : CheckResult
} }
internal fun Project.checkExperimentalTargetsWithSkikoIsEnabled() = afterEvaluate { private fun Project.checkExperimentalTargetsWithSkikoIsEnabled() {
val mppExt = project.extensions.findByType(KotlinMultiplatformExtension::class.java) ?: return@afterEvaluate val mppExt = project.mppExt
val failedResults = mppExt.targets.map { checkTarget(it) } val failedResults = mppExt.targets.map { checkTarget(it) }
.filterIsInstance<CheckResult.Fail>() .filterIsInstance<CheckResult.Fail>()
.distinctBy { it.target } .distinctBy { it.target }

11
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() { class GradlePluginTest : GradlePluginTestBase() {
@Test @Test
fun skikoWasm() = with(testProject(TestProjects.skikoWasm)) { 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 { gradle(":build").checks {
check.taskSuccessful(":unpackSkikoWasmRuntimeJs") check.taskSuccessful(":unpackSkikoWasmRuntimeJs")
check.taskSuccessful(":compileKotlinJs") check.taskSuccessful(":compileKotlinJs")

12
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<out String>, runnerFn: GradleRunner.() -> BuildResult): BuildResult {
if (TestProperties.gradleConfigurationCache) { if (TestProperties.gradleConfigurationCache) {
if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) { if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) {
// Gradle 7.* does not use the configuration cache in the same build. // 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. // 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. // 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) // 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<out String>.withDryRun(): Array<String> { private fun Array<out String>.withDryRun(): Array<String> {

7
gradle-plugins/compose/src/test/test-projects/misc/skikoWasm/build.gradle

@ -29,3 +29,10 @@ kotlin {
compose.experimental { compose.experimental {
web.application {} 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")
}
}
Loading…
Cancel
Save