Reputation: 1616
I don't see in documentations. When I build a multiplatform compose project based on JVM, how can I deliver a desktop package or app so others can execute it easily?
==========
Update:
I specified the following in build.gradle.kts under desktop
compose.desktop {
application {
mainClass = "MainKt"
javaHome = System.getenv("JDK_18")
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "MyApp"
packageVersion = "1.0.0"
}
}
}
Then running ./gradlew packageDeb
(on Ubuntu) I got a .deb package, which I could install on Ubuntu and run. Very cool. (It looks there is no option building it from Intellij and I have to do it with gradlew)
Then I tried ./gradlew packageMsi
, it came back very quickly saying build successful, but I get no .msi file generated. Do I have to build it from a Windows machine?
I haven't tried to build the dmg for Mac as it's advised to use XCode on the Mac to generate a signed version.
==============
Update 1:
So based on description of jPackage from Oracle:
Application packages must be built on the target platform. The system used for packaging must contain the application, a JDK, and software needed by the packaging tool.
To package your application for multiple platforms, you must run the packaging tool on each platform. If you want more than one format for a platform, you must run the tool once for each format.
Upvotes: 4
Views: 4879
Reputation: 76779
In order to launch the JVM application with an "Application" run-configuration, one has to launch the @Composable App
from main.kt
. Reduced to the least required, this looks about alike this ...
File build.gradle.kts
:
plugins {
kotlin("jvm") version "2.1.0"
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
id("org.jetbrains.compose") version "1.7.1"
}
dependencies {
implementation(compose.desktop.currentOs)
testImplementation(kotlin("test"))
testImplementation(compose.desktop.uiTestJUnit4)
}
File main.kt
:
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
File App.kt
:
@Preview
@Composable
fun App() {
MaterialTheme {
...
}
}
targetFormats
may be AppImage
, Deb
, Rpm
, Dmg
, Pkg
, Exe
, Msi
.
What one can actually build depends on compose.desktop.currentOs
.
The command to produce MSI would be: .\gradlew.bat packageMsi
Besides, one can access any Gradle task in the IDE Gradle tab ...
Upvotes: 0
Reputation: 950
For anyone looking to publish desktop apps, conveyor is an easy solution: https://conveyor.hydraulic.dev/15.0/
It allows you to easily publish desktop apps.
After installing conveyor, to setup:
id("dev.hydraulic.conveyor")
version "1.10" under plugins in build.gradle app level.group = "appName"
and version = "x.y.z"
in the build.gradle file.jar
files in build/libs folder.conveyer.conf
file to root folder of project. Example: include "#!./gradlew -q printConveyorConfig"
include "/stdlib/jdk/17/amazon.conf"
app {
display-name = "AppName"
vcs-url = "https://example.com/my-vcs-url"
fsname = "my-package-name"
icons = ic.svg
contact-email = "[email protected]"
vendor = "Vendor"
site {
github {
oauth-token = "github-token"
pages-branch = "gh-pages"
}
}
mac {
info-plist {
CFBundleDocumentTypes = [
{
CFBundleTypeName = Folders
CFBundleTypeRole = Viewer
LSItemContentTypes = [ public.folder ]
LSHandlerRank = Alternate
}
]
NSHumanReadableCopyright = "Copyright © Year, Example."
}
}
}
conveyor.compatibility-level = 15
Conveyor is free for open-source projects.
Add ic.svg to root of project
Run conveyor run
to test
run conveyor make copied-site
to release
Upvotes: 0