DEV Community

Cover image for How to use Hydraulic Conveyor with KMP Compose for Desktop
ColtonIdle
ColtonIdle

Posted on • Edited on

How to use Hydraulic Conveyor with KMP Compose for Desktop

  1. Download a new project from https://kmp.jetbrains.com/ and be sure to select a desktop application
  2. In your app level build.gradle add id("dev.hydraulic.conveyor") version "1.12"

You may want to include it in your root build.gradle with apply false if you get any issues in the future as per: https://programminghard.dev/gradle-plugins-best-practices/

  1. In app level build.gradle.kts add (this does not go into any block. just goes at the top level of this file)
version = "1.0"
Enter fullscreen mode Exit fullscreen mode

This is needed even though a version is already declared in the nativeDistributions block.

  1. In app build.gradle.kts under jvm("desktop") add
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(21))
        vendor.set(JvmVendorSpec.JETBRAINS)
    }
Enter fullscreen mode Exit fullscreen mode
  1. In app build.gradle.kts at the top level add a dependencies block (it most likely wont be there unless you're building an android app). You will already have 2 other dependencies blocks most likely, but those are nested inside of the kotlin and sourceSets blocks. This one is needed at the top level.
 dependencies {
     debugImplementation(compose.uiTooling) <=== This will only be here if you are building an android app

    // Use the configurations created by the Conveyor plugin to tell Gradle/Conveyor where to find the artifacts for each platform.
    linuxAmd64(compose.desktop.linux_x64)
    macAmd64(compose.desktop.macos_x64)
    macAarch64(compose.desktop.macos_arm64)
    windowsAmd64(compose.desktop.windows_x64)
 }
Enter fullscreen mode Exit fullscreen mode
  1. In app level build.gradle.kts you will find
         nativeDistributions {
             targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
             packageName = "org.example.project"
             packageVersion = "1.0.0"
         }
     }
 }
Enter fullscreen mode Exit fullscreen mode

but for some reason conveyor doesn't work with package names that are reverse dns. Replace that with packageName = "example-project"

  1. In app level build.gradle.kts at the top level you can add
// Work around temporary Compose bugs.
configurations.all {
    attributes {
        // https://github.com/JetBrains/compose-jb/issues/1404#issuecomment-1146894731
        attribute(Attribute.of("ui", String::class.java), "awt")
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. In settings.gradle.kts you can add
plugins {
    id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0")
}
Enter fullscreen mode Exit fullscreen mode

This has to be declared after your plugin dependency block.

  1. Add a minimal conveyor.conf file
include "#!./gradlew -q printConveyorConfig"

app {
  display-name = My Amazing Project
  site.base-url = localhost/some/path
}
conveyor.compatibility-level = 17

Enter fullscreen mode Exit fullscreen mode

See: https://conveyor.hydraulic.dev/17.0/configs/ for more configuration

  1. Run ./gradlew desktopJar (Conveyor doesn't trigger your build for you yet so you still need to run this)
  2. Run conveyor make site
  3. When you make an update to your desktop app, update the version number we declared earlier, run ./gradlew desktopJar, and then conveyor make site --overwrite

πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰

Note: You may want to call ./gradlew proguardReleaseJars instead of desktopJar, but you need to setup proguard. I have not done this yet, but I will link it here if I figure out how to do that.

Top comments (0)