Browse Source

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
pull/328/head
Alexey Tsvetkov 4 years ago committed by Alexey Tsvetkov
parent
commit
0d68dea6de
  1. 19
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt
  2. 6
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt
  3. 2
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt
  4. 19
      gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt
  5. 23
      gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle

19
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<Jar> =
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") })
}
}
}

6
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 }

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

19
gradle-plugins/compose/src/test/test-projects/application/jvm/src/main/kotlin/main.kt

@ -1 +1,18 @@
fun main() {}
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)
}
}
}

23
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"
}
}
}
}

Loading…
Cancel
Save