https://kotlinlang.org logo
Title
t

Timo Drick

11/21/2020, 12:32 AM
It would be nice if we could bunlde a compose-desktop app as fat-jar (Jar which contains all dependency) I know that there is this nativeDistributions support in the compose.desktop plugin. But it generates very complicated install packages (Even for small projects over 100mb). Are there any plans to support this?
s

suresh

11/21/2020, 3:01 AM
Compose is a normal jvm app. You can apply the shadow plugin to create the fat jar.
plugins {
    application
    kotlin("jvm") version "1.4.10"
    id("org.jetbrains.compose") version "0.2.0-build127"
    id("com.github.johnrengelman.shadow") version "6.1.0"
}

...

application {
    mainClass.set("MainKt")
    mainClassName = mainClass.get()
}
$ ./gradlew build 
$ java -jar build/libs/compose-desktop-sample-1.0.0-all.jar
Since they removed
compose.desktop.all
dependency, i think the fat jar won't be cross platform. You have to build it for each platform
o

olonho

11/21/2020, 9:27 AM
note, that you can manually enumerate all the platforms you want to support
👍 1
t

Timo Drick

11/21/2020, 11:58 AM
i can not use the application plugin: > Cannot add task 'run' as a task with that name already exists.
But shadowJar works.
But configuration must be done this way:
tasks {
    named<ShadowJar>("shadowJar") {
        archiveBaseName.set(packageName)
        mergeServiceFiles()
        manifest {
            attributes(mapOf("Main-Class" to mainClass))
        }
    }
}
c

ckloss

11/21/2020, 12:31 PM
As far as I know, there is no way to use the plugin application together with the compose.desktop block in the same script. So the error "Cannot add task 'run' ..."
o

olonho

11/21/2020, 2:32 PM
Yep, please file a feature request for fat jar in Compose plugin
a

Animesh Sahu

11/21/2020, 5:46 PM
Though, you can pack native distributions. Last time I checked, the windows package was ~41mb for a simple hello world screen.
t

Timo Drick

11/21/2020, 7:01 PM
Maybe it would also be cool to use something like proguard to strip the unused classes like in Android.
a

Animesh Sahu

11/22/2020, 2:54 AM
@Timo Drick its already quite optimized, it packs JRE, skia library, its JNI binding, and compose itself with your code. JRE is > 50MB iirc, jpackage links only required part of JRE in the executable.
Kotlin/Native one should be under 15MB more like 10MB as ~8MB is skia library iirc, which might be implemented in future.
👍 1