Browse Source

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
pull/973/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
227834f963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt
  2. 1
      idea-plugin/examples/simple-preview-example/mpp-jvm/build.gradle.kts
  3. 2
      idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts

13
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<String> =
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<File>.pathString(): String =
private fun Sequence<File>.pathString(): String =
joinToString(File.pathSeparator) { it.absolutePath }
private class GradlePreviewLoggerAdapter(

1
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") {

2
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)
}
Loading…
Cancel
Save