Browse Source

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

Resolves #3169
pull/3174/head
Alexey Tsvetkov 2 years ago committed by GitHub
parent
commit
baeeec8abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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.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> {
project.afterEvaluate {
configureDesktop(project, desktopExtension)
project.configureExperimental(composeExtension, experimentalExtension)
project.checkExperimentalTargetsWithSkikoIsEnabled()
project.configureExperimentalTargetsFlagsCheck()
project.tasks.withType(KotlinCompile::class.java).configureEach {
it.kotlinOptions.apply {

15
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<CheckResult.Fail>()
.distinctBy { it.target }

11
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")

12
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<out String>, 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<out String>.withDryRun(): Array<String> {

7
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")
}
}
Loading…
Cancel
Save