Browse Source

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
pull/2545/head v1.3.0-alpha01-dev853
Igor Demin 2 years ago committed by GitHub
parent
commit
f35e286958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt
  2. 31
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  3. 2
      gradle-plugins/gradle/wrapper/gradle-wrapper.properties

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

@ -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}")
)

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

@ -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)

2
gradle-plugins/gradle/wrapper/gradle-wrapper.properties vendored

@ -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

Loading…
Cancel
Save