mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 08:11:20 +00:00
Fix Preview compatibility with Gradle configuration cache (#2470)
* Fix Preview compatability with Gradle configuiration cache Fixes https://github.com/JetBrains/compose-jb/issues/2376 * A test for Gradle configuration cache And Gradle 7.5.1
This commit is contained in:
@@ -37,12 +37,12 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
|
||||
project.providers.gradleProperty("compose.desktop.preview.ide.port")
|
||||
|
||||
@get:InputFiles
|
||||
internal val uiTooling = project.configurations.detachedConfiguration(
|
||||
internal val uiTooling: FileCollection = project.configurations.detachedConfiguration(
|
||||
project.dependencies.create("org.jetbrains.compose.ui:ui-tooling-desktop:${ComposeBuildConfig.composeVersion}")
|
||||
).apply { isTransitive = false }
|
||||
|
||||
@get:InputFiles
|
||||
internal val hostClasspath = project.configurations.detachedConfiguration(
|
||||
internal val hostClasspath: FileCollection = project.configurations.detachedConfiguration(
|
||||
project.dependencies.create("org.jetbrains.compose:preview-rpc:${ComposeBuildConfig.composeVersion}")
|
||||
)
|
||||
|
||||
|
||||
@@ -36,7 +36,12 @@ class GradlePluginTest : GradlePluginTestBase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun configurePreview() {
|
||||
fun configurePreviewWithoutConfigurationCache() = configurePreview(withConfigurationCache = false)
|
||||
|
||||
@Test
|
||||
fun configurePreviewWithConfigurationCache() = configurePreview(withConfigurationCache = true)
|
||||
|
||||
private fun configurePreview(withConfigurationCache: Boolean) {
|
||||
val isAlive = AtomicBoolean(true)
|
||||
val receivedConfigCount = AtomicInteger(0)
|
||||
val port = AtomicInteger(-1)
|
||||
@@ -45,7 +50,7 @@ class GradlePluginTest : GradlePluginTestBase() {
|
||||
soTimeout = 10_000
|
||||
}
|
||||
port.set(serverSocket.localPort)
|
||||
try {
|
||||
serverSocket.use {
|
||||
while (isAlive.get()) {
|
||||
try {
|
||||
val socket = serverSocket.accept()
|
||||
@@ -63,9 +68,6 @@ class GradlePluginTest : GradlePluginTestBase() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
serverSocket.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +82,7 @@ class GradlePluginTest : GradlePluginTestBase() {
|
||||
}
|
||||
|
||||
try {
|
||||
testConfigureDesktopPreivewImpl(port.get())
|
||||
testConfigureDesktopPreviewImpl(port.get(), withConfigurationCache)
|
||||
} finally {
|
||||
isAlive.set(false)
|
||||
connectionThread.interrupt()
|
||||
@@ -94,20 +96,31 @@ class GradlePluginTest : GradlePluginTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun testConfigureDesktopPreivewImpl(port: Int) {
|
||||
private fun testConfigureDesktopPreviewImpl(port: Int, withConfigurationCache: Boolean) {
|
||||
check(port > 0) { "Invalid port: $port" }
|
||||
with(testProject(TestProjects.jvmPreview)) {
|
||||
val portProperty = "-Pcompose.desktop.preview.ide.port=$port"
|
||||
val previewTargetProperty = "-Pcompose.desktop.preview.target=PreviewKt.ExamplePreview"
|
||||
val jvmTask = ":jvm:configureDesktopPreview"
|
||||
gradle(jvmTask, portProperty, previewTargetProperty)
|
||||
val configurationCacheArg = "--configuration-cache"
|
||||
val jvmRunner = if (withConfigurationCache) {
|
||||
gradle(jvmTask, portProperty, previewTargetProperty, configurationCacheArg)
|
||||
} else {
|
||||
gradle(jvmTask, portProperty, previewTargetProperty)
|
||||
}
|
||||
jvmRunner
|
||||
.build()
|
||||
.checks { check ->
|
||||
check.taskOutcome(jvmTask, TaskOutcome.SUCCESS)
|
||||
}
|
||||
|
||||
val mppTask = ":mpp:configureDesktopPreviewDesktop"
|
||||
gradle(mppTask, portProperty, previewTargetProperty)
|
||||
val mppRunner = if (withConfigurationCache) {
|
||||
gradle(mppTask, portProperty, previewTargetProperty, configurationCacheArg)
|
||||
} else {
|
||||
gradle(mppTask, portProperty, previewTargetProperty)
|
||||
}
|
||||
mppRunner
|
||||
.build()
|
||||
.checks { check ->
|
||||
check.taskOutcome(mppTask, TaskOutcome.SUCCESS)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
Reference in New Issue
Block a user