LXJ
LXJ

Reputation: 1616

How to deliver a desktop app of Kotlin multiplatform project?

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

Answers (2)

Martin Zeitler
Martin Zeitler

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 ... enter image description here

Upvotes: 0

MYJ World
MYJ World

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:

  1. Add id("dev.hydraulic.conveyor") version "1.10" under plugins in build.gradle app level.
  2. Add: group = "appName" and version = "x.y.z" in the build.gradle file.
  3. Sync gradle
  4. Rebuild project to get the jar files in build/libs folder.
  5. Add 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.

  1. Add ic.svg to root of project

  2. Run conveyor run to test

  3. run conveyor make copied-site to release

Upvotes: 0

Related Questions