Browse Source

Make desktop preview task fully configuration cache compliant (#4410)

The issue was in a case where there wasn't a direct dependency on the
skiko artifact, the task would attempt to get one at task execution
time. This moves that to task configuration time.
pull/4577/head v1.6.10-dev1561
Eliezer Graber 8 months ago committed by GitHub
parent
commit
93f37251f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/internal/configurePreview.kt
  2. 14
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt
  3. 9
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  4. 17
      gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/build.gradle
  5. 21
      gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/src/commonMain/kotlin/composable.kt
  6. 8
      gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/src/commonMain/kotlin/preview.kt
  7. 2
      gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/settings.gradle

1
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/internal/configurePreview.kt

@ -34,6 +34,7 @@ private fun registerConfigurePreviewTask(
) { previewTask ->
runtimeFiles.configureUsageBy(previewTask) { (runtimeJars, _) ->
previewClasspath = runtimeJars
skikoRuntime = tryGetSkikoRuntimeIfNeeded()
}
}
}

14
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt

@ -18,6 +18,9 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
@get:InputFiles
internal lateinit var previewClasspath: FileCollection
@get:InputFiles
internal lateinit var skikoRuntime: FileCollection
@get:Internal
internal val javaHome: Property<String> = objects.notNullProperty<String>().apply {
set(providers.systemProperty("java.home"))
@ -58,7 +61,7 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
val previewClasspathString =
(previewClasspath.files.asSequence() +
uiTooling.files.asSequence() +
tryGetSkikoRuntimeFilesIfNeeded().asSequence()
skikoRuntime.files.asSequence()
).pathString()
val gradleLogger = logger
@ -78,7 +81,7 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
}
}
private fun tryGetSkikoRuntimeFilesIfNeeded(): Collection<File> {
internal fun tryGetSkikoRuntimeIfNeeded(): FileCollection {
try {
var hasSkikoJvm = false
var hasSkikoJvmRuntime = false
@ -96,21 +99,20 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
}
}
}
if (hasSkikoJvmRuntime) return emptyList()
if (hasSkikoJvmRuntime) return project.files()
if (hasSkikoJvm && !skikoVersion.isNullOrBlank()) {
val skikoRuntimeConfig = project.detachedDependency(
return project.detachedDependency(
groupId = "org.jetbrains.skiko",
artifactId = "skiko-awt-runtime-${currentTarget.id}",
version = skikoVersion
).excludeTransitiveDependencies()
return skikoRuntimeConfig.files
}
} catch (e: Exception) {
// OK
}
return emptyList()
return project.files()
}
private fun Sequence<File>.pathString(): String =

9
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

@ -288,9 +288,9 @@ class GradlePluginTest : GradlePluginTestBase() {
connectionThread.join(5000)
}
val expectedReceivedConfigCount = 2
val expectedReceivedConfigCount = 3
val actualReceivedConfigCount = receivedConfigCount.get()
check(actualReceivedConfigCount == 2) {
check(actualReceivedConfigCount == expectedReceivedConfigCount) {
"Expected to receive $expectedReceivedConfigCount preview configs, got $actualReceivedConfigCount"
}
}
@ -309,6 +309,11 @@ class GradlePluginTest : GradlePluginTestBase() {
gradle(mppTask, portProperty, previewTargetProperty).checks {
check.taskSuccessful(mppTask)
}
val commonTask = ":common:configureDesktopPreviewDesktop"
gradle(commonTask, portProperty, previewTargetProperty).checks {
check.taskSuccessful(commonTask)
}
}
}

17
gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/build.gradle

@ -0,0 +1,17 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform'
id 'org.jetbrains.compose'
}
kotlin {
jvm('desktop') {}
sourceSets {
commonMain.dependencies {
api compose.runtime
api compose.foundation
api compose.material
api compose.uiTooling
}
}
}

21
gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/src/commonMain/kotlin/composable.kt

@ -0,0 +1,21 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.runtime.*
@Composable
fun ExampleComposable() {
var text by remember { mutableStateOf("Hello, World!") }
Button(onClick = {
text = "Hello, $platformName!"
}) {
Text(text)
}
}
val platformName: String = "Desktop"

8
gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/common/src/commonMain/kotlin/preview.kt

@ -0,0 +1,8 @@
import androidx.compose.runtime.Composable
import androidx.compose.desktop.ui.tooling.preview.Preview
@Preview
@Composable
fun ExamplePreview() {
ExampleComposable()
}

2
gradle-plugins/compose/src/test/test-projects/misc/jvmPreview/settings.gradle

@ -25,4 +25,4 @@ dependencyResolutionManagement {
}
}
rootProject.name = 'jvmPreview'
include(':jvm', ':mpp')
include(':common', ':jvm', ':mpp')

Loading…
Cancel
Save