Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make desktop preview task fully configuration cache compliant #4410

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private fun registerConfigurePreviewTask(
) { previewTask ->
runtimeFiles.configureUsageBy(previewTask) { (runtimeJars, _) ->
previewClasspath = runtimeJars
skikoRuntime = tryGetSkikoRuntimeIfNeeded()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand All @@ -78,7 +81,7 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
}
}

private fun tryGetSkikoRuntimeFilesIfNeeded(): Collection<File> {
internal fun tryGetSkikoRuntimeIfNeeded(): FileCollection {
try {
var hasSkikoJvm = false
var hasSkikoJvmRuntime = false
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,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"
}
}
Expand All @@ -343,6 +343,11 @@ class GradlePluginTest : GradlePluginTestBase() {
gradle(mppTask, portProperty, previewTargetProperty).checks {
check.taskSuccessful(mppTask)
}

val commonTask = ":common:configureDesktopPreviewDesktop"
gradle(commonTask, portProperty, previewTargetProperty).checks {
check.taskSuccessful(commonTask)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import androidx.compose.runtime.Composable
import androidx.compose.desktop.ui.tooling.preview.Preview

@Preview
@Composable
fun ExamplePreview() {
ExampleComposable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pluginManagement {
}
}
rootProject.name = 'jvmPreview'
include(':jvm', ':mpp')
include(':common', ':jvm', ':mpp')