From 227834f963918f2e7412d34fc1d5e3aa3ea37063 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Mon, 2 Aug 2021 11:47:06 +0300 Subject: [PATCH] Allow preview to work without explicit dependency on compose.uiTooling (#972) Add runtime-only module org.jetbrains.compose.ui:ui-tooling-desktop to preview classpath in configureDesktopPreview task --- .../tasks/AbstractConfigureDesktopPreviewTask.kt | 13 ++++++++++--- .../simple-preview-example/mpp-jvm/build.gradle.kts | 1 - .../pure-jvm/build.gradle.kts | 2 -- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt index 4333b447da..37c6e0623b 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt @@ -35,6 +35,11 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask( internal val idePort: Provider = project.providers.gradleProperty("compose.desktop.preview.ide.port") + @get:InputFiles + internal val uiTooling = 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( project.dependencies.create("org.jetbrains.compose:preview-rpc:${ComposeBuildConfig.composeVersion}") @@ -44,9 +49,11 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask( fun run() { val hostConfig = PreviewHostConfig( javaExecutable = javaExecutable(javaHome.get()), - hostClasspath = hostClasspath.files.pathString() + hostClasspath = hostClasspath.files.asSequence().pathString() ) - val previewClasspathString = previewClasspath.files.pathString() + val previewClasspathString = + (previewClasspath.files.asSequence() + uiTooling.files.asSequence()) + .pathString() val gradleLogger = logger val previewLogger = GradlePreviewLoggerAdapter(gradleLogger) @@ -65,7 +72,7 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask( } } - private fun Collection.pathString(): String = + private fun Sequence.pathString(): String = joinToString(File.pathSeparator) { it.absolutePath } private class GradlePreviewLoggerAdapter( diff --git a/idea-plugin/examples/simple-preview-example/mpp-jvm/build.gradle.kts b/idea-plugin/examples/simple-preview-example/mpp-jvm/build.gradle.kts index 58ca836f5c..132deb883d 100644 --- a/idea-plugin/examples/simple-preview-example/mpp-jvm/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/mpp-jvm/build.gradle.kts @@ -14,7 +14,6 @@ kotlin { api(compose.runtime) api(compose.foundation) api(compose.material) - api(compose.uiTooling) } } named("desktopMain") { diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts index 22bf3d8f3a..4a21377d49 100644 --- a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts @@ -7,6 +7,4 @@ plugins { dependencies { implementation(compose.desktop.currentOs) - // todo: remove after update - implementation(compose.uiTooling) } \ No newline at end of file