Browse Source

Add skiko-runtime-jvm jar to preview classpath if necessary (#987)

pull/994/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
4697b0fed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/preview/tasks/AbstractConfigureDesktopPreviewTask.kt

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

@ -7,6 +7,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
import org.jetbrains.compose.ComposeBuildConfig
import org.jetbrains.compose.desktop.application.internal.currentTarget
import org.jetbrains.compose.desktop.application.internal.javaExecutable
import org.jetbrains.compose.desktop.application.internal.notNullProperty
import org.jetbrains.compose.desktop.tasks.AbstractComposeDesktopTask
@ -52,8 +53,10 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
hostClasspath = hostClasspath.files.asSequence().pathString()
)
val previewClasspathString =
(previewClasspath.files.asSequence() + uiTooling.files.asSequence())
.pathString()
(previewClasspath.files.asSequence() +
uiTooling.files.asSequence() +
tryGetSkikoRuntimeFilesIfNeeded().asSequence()
).pathString()
val gradleLogger = logger
val previewLogger = GradlePreviewLoggerAdapter(gradleLogger)
@ -72,6 +75,39 @@ abstract class AbstractConfigureDesktopPreviewTask : AbstractComposeDesktopTask(
}
}
private fun tryGetSkikoRuntimeFilesIfNeeded(): Collection<File> {
try {
var hasSkikoJvm = false
var hasSkikoJvmRuntime = false
var skikoVersion: String? = null
for (file in previewClasspath.files) {
if (file.name.endsWith(".jar")) {
if (file.name.startsWith("skiko-jvm-runtime-")) {
hasSkikoJvmRuntime = true
continue
} else if (file.name.startsWith("skiko-jvm-")) {
hasSkikoJvm = true
skikoVersion = file.name
.removePrefix("skiko-jvm-")
.removeSuffix(".jar")
}
}
}
if (hasSkikoJvmRuntime) return emptyList()
if (hasSkikoJvm && skikoVersion != null && skikoVersion.isNotBlank()) {
val skikoRuntimeConfig = project.configurations.detachedConfiguration(
project.dependencies.create("org.jetbrains.skiko:skiko-jvm-runtime-${currentTarget.id}:$skikoVersion")
).apply { isTransitive = false }
return skikoRuntimeConfig.files
}
} catch (e: Exception) {
// OK
}
return emptyList()
}
private fun Sequence<File>.pathString(): String =
joinToString(File.pathSeparator) { it.absolutePath }

Loading…
Cancel
Save