DEV Community

Cover image for From Swing to Compose Desktop #6
Thomas Künneth
Thomas Künneth

Posted on • Edited on

From Swing to Compose Desktop #6

Welcome to the 6. post about my journey of transforming a Java Swing app to Compose for Desktop. Today I will focus on deployment. That is, how to create a ready-to-run app. Luckily, this is very simple:

compose.desktop {
    application {
        mainClass = "com.thomaskuenneth.tkdupefinder.MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg)
            packageName = "TKDupeFinder"
            version = "0.1-SNAPSHOT"
            description = "Find duplicate files"
            copyright = "© 2020 Thomas Kuenneth. All rights reserved."
            vendor = "Thomas Kuenneth"
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

If you add this snippet to your build.gradle.kts file, you can initiate the creation of native executables like this:

Creating native executables

My example above creates a .dmg file which looks like this (when it is opened):

A beautiful disk image

You can find these artifacts in build/compose/binaries/main, assuming your module is called main. The .dmg file is in, you guessed it, dmg. Duke certainly is lovely, but you may want to replace him with an individual app icon. It needs to be provided in OS-specific formats, namely .icns for macOS, .ico for Windows and .png for Linux. Update your build file like this:

nativeDistributions {
  macOS {
    iconFile.set(project.file("app_icon.icns"))
  }
  windows {
    iconFile.set(project.file("app_icon.ico"))
  }
  linux {
    iconFile.set(project.file("app_icon.png"))
  }
}
Enter fullscreen mode Exit fullscreen mode

Files named accordingly need to be located in the project base directory. Opening your app produces a nice looking menubar with an about dialog:

A copyright box

As you can see, all relevant info is grabbed automatically from the build file, even the app name and copyright info are set accordingly. The only thing I seem to not be able to set is the name for About and Quit. Did you find out how to do this. Please tell me in the comments.


From Swing to Jetpack Compose Desktop #1
From Swing to Jetpack Compose Desktop #2
From Swing to Compose Desktop #3
From Swing to Compose Desktop #4
From Swing to Compose Desktop #5

Top comments (0)