From 0d68dea6de443132f7a42f77aca420c2f5dfc5ee Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 25 Jan 2021 10:40:31 +0300 Subject: [PATCH] Filter out non-jar files in runtime classpath WiX linker fails to find class files of inlined functions for some reason (maybe because of '$' character in name or long paths) Fixes #196 --- .../application/dsl/ConfigurationSource.kt | 19 +++++++++------ .../internal/configureApplication.kt | 6 ++--- .../compose/DesktopApplicationTest.kt | 2 +- .../application/jvm/src/main/kotlin/main.kt | 19 ++++++++++++++- .../application/mpp/build.gradle | 23 ++++++++++++++++++- 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt index 46951602c8..4094004057 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt @@ -9,7 +9,9 @@ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget internal sealed class ConfigurationSource { abstract val jarTaskName: String - abstract val runtimeClasspath: FileCollection + + abstract fun runtimeClasspath(project: Project): FileCollection + fun jarTask(project: Project): TaskProvider = project.tasks.named(jarTaskName, Jar::class.java) @@ -17,8 +19,11 @@ internal sealed class ConfigurationSource { override val jarTaskName: String get() = sourceSet.jarTaskName - override val runtimeClasspath: FileCollection - get() = sourceSet.runtimeClasspath + override fun runtimeClasspath(project: Project): FileCollection = + project.objects.fileCollection().apply { + from(jarTask(project).flatMap { it.archiveFile }) + from(sourceSet.runtimeClasspath.filter { it.path.endsWith(".jar") }) + } } @@ -26,10 +31,10 @@ internal sealed class ConfigurationSource { override val jarTaskName: String get() = target.artifactsTaskName - override val runtimeClasspath: FileCollection - get() = target.project.objects.fileCollection().apply { - from(jarTask(target.project).flatMap { it.archiveFile }) - from(target.compilations.getByName("main").runtimeDependencyFiles) + override fun runtimeClasspath(project: Project): FileCollection = + project.objects.fileCollection().apply { + from(jarTask(project).flatMap { it.archiveFile }) + from(target.compilations.getByName("main").runtimeDependencyFiles.filter { it.path.endsWith(".jar") }) } } } \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt index fb694bdeee..2dc3c7d18e 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt @@ -125,7 +125,7 @@ internal fun AbstractJPackageTask.configurePackagingTask( app._configurationSource?.let { configSource -> dependsOn(configSource.jarTaskName) - files.from(configSource.runtimeClasspath) + files.from(configSource.runtimeClasspath(project)) launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile })) } @@ -188,7 +188,7 @@ private fun JavaExec.configureRunTask(app: Application) { app._configurationSource?.let { configSource -> dependsOn(configSource.jarTaskName) - cp.from(configSource.runtimeClasspath) + cp.from(configSource.runtimeClasspath(project)) } classpath = cp @@ -207,7 +207,7 @@ private fun Jar.configurePackageUberJarForCurrentOS(app: Application) { app._configurationSource?.let { configSource -> dependsOn(configSource.jarTaskName) - from(flattenJars(configSource.runtimeClasspath)) + from(flattenJars(configSource.runtimeClasspath(project))) } app.mainClass?.let { manifest.attributes["Main-Class"] = it } diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt index fa9c3badff..dc5f83edac 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt @@ -57,7 +57,7 @@ class DesktopApplicationTest : GradlePluginTestBase() { OS.Windows -> "msi" OS.MacOS -> "dmg" } - file("build/compose/binaries/main/$ext/simple-1.0.$ext") + file("build/compose/binaries/main/$ext/TestPackage-1.0.$ext") .checkExists() assertEquals(TaskOutcome.SUCCESS, result.task(":package${ext.capitalize()}")?.outcome) assertEquals(TaskOutcome.SUCCESS, result.task(":package")?.outcome) diff --git a/gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt b/gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt index 78e3db2779..f3f7e65f9e 100644 --- a/gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt +++ b/gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt @@ -1 +1,18 @@ -fun main() {} \ No newline at end of file +import androidx.compose.desktop.Window +import androidx.compose.material.Text +import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme +import androidx.compose.runtime.* + +fun main() = Window { + val scope = rememberCoroutineScope() + var text by remember { mutableStateOf("Hello, World!") } + + MaterialTheme { + Button(onClick = { + text = "Hello, Desktop!" + }) { + Text(text) + } + } +} \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle b/gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle index 7c5ee02c76..a69d2f10f9 100644 --- a/gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle +++ b/gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle @@ -33,8 +33,29 @@ compose.desktop { application { mainClass = "MainKt" nativeDistributions { - version = "1.0" targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + + version = "1.0" + packageName = "TestPackage" + description = "Test description" + copyright = "Test Copyright Holder" + vendor = "Test Vendor" + + linux { + shortcut = true + packageName = "compose" + debMaintainer = "example@example.com" + menuGroup = "menu-group" + } + windows { + console = true + dirChooser = true + perUserInstall = true + shortcut = true + menu = true + menuGroup = "compose" + upgradeUuid = "2d6ff464-75be-40ad-a256-56420b9cc374" + } } } }