Integrating Conveyor with Gradle projects¶
conveyor.conf¶
Config can be extracted from your build system using a simple plugin. The Gradle plugin doesn't replace or drive the package build process itself: you still do that using the conveyor
command line tool. The plugin is narrowly scoped to generating configuration and nothing more. If you want Gradle to run Conveyor you can add a normal exec task to do so.
The hand-written conveyor.conf
file will typically look like this:
conveyor.conf | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
- This is a hashbang include. The given program will be run and the output included as if it were a static HOCON file.
- You may not need to set this if the display name of your project is trivially derivable from the name of the Gradle project. Use
printConveyorConfig
to see what the plugin guessed. - This is where the created packages will look for update metadata.
- The templates come with pre-rendered icons in both square and rounded rectangle styles. This bit of config uses square by default and rounded rects on macOS only, but that's just a style choice to fit in with the native expectations. You can use whatever icons you like. They should be rendered as PNGs in a range of square sizes, ideally 32x32, 64x64, 128x128 etc up to 1024x1024.
Many settings are missing (e.g. app.rdns-name
) because they'll be read from your build configuration.
Gradle plugin¶
To add the plugin:
settings.gradle.kts | |
---|---|
1 2 3 4 5 6 |
|
build.gradle.kts | |
---|---|
1 2 3 |
|
settings.gradle | |
---|---|
1 2 3 4 5 6 |
|
build.gradle | |
---|---|
1 2 3 |
|
The plugin adds two tasks, printConveyorConfig
and writeConveyorConfig
. The first prints the generated config to stdout, and the second writes it to an output file. By default this is called generated.conveyor.conf
but can be changed.
- Run
./gradlew -q printConveyorConfig
and examine the output.
Note
The plugin can read config from other plugins like the Java application plugin, the Jetpack Compose plugin and the OpenJFX plugin. It can in some cases identify which JDK you want to bundle with your app from the Java toolchains setting. If it doesn't then it'll emit a comment to the generated config explaining why not, and you'll have to add another line of config to import a JDK.
Hashbang includes¶
The hashbang include you saw earlier will run Gradle each time you invoke Conveyor to extract config. This approach adds a slight delay to each Conveyor run, because even with the Gradle daemon this process isn't instant, but it does mean your config is always synced. You can also write include required("generated.conveyor.conf")
and run gradle writeConveyorConfig
when you change your Gradle build. This avoids any delay from involving Gradle but means your settings can get out of sync. Wrapping the packaging process with a script lets you have the best of both worlds.
Machine-specific dependencies¶
Sometimes you need different versions of a library depending on which OS you use. A good example is when packaging Jetpack Compose apps (see below for an example). The Conveyor plugin provides a simple solution for this in the form of per-machine configurations. The one that matches the host OS is always used, and the others are emitted as config for Conveyor so it can build packages for other operating systems. The available configurations are named linuxAmd64
, macAmd64
, macAarch64
and windowsAmd64
.
Adapting a Compose Desktop app¶
For Jetpack Compose Desktop apps a bit more work is required. Different Conveyor plugin versions support different Compose Desktop versions:
- For Compose 1.2, use Conveyor plugin
1.2
or higher. - For Compose 1.0/1.1, use Conveyor plugin
1.0.1
. You'll need to import a JDK yourself.
If you use the wrong one you'll get a NoSuchMethodError
exception. Both JVM and Multiplatform Kotlin plugins are supported.
- Add machine-specific dependencies to the top level of your build file.
1 2 3 4 5 6 |
|
- Add workarounds for Compose issues.
You'll need to add the following snippet to your build file (translate to Groovy if not using Kotlin Gradle syntax).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Kotlin Multiplatform¶
If using Kotlin Multiplatform:
- Add
withJava()
and also ensure you're using the right version of the Kotlin standard library in your project dependencies.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
- Add
kotlin.mpp.stability.nowarn=true
to yourgradle.properties
file, to silence a warning printed during build configuration time that would interfere with config import otherwise.
Setting icons¶
Compose expects to set the window icon itself, rather than having it be taken from the executable or package automatically. You can use code like this to ensure the window icon is always set correctly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Adapting a JavaFX app¶
This is almost exactly like a normal Gradle app except that a bit more work is required for icons. Firstly, bundle the icons into your app as data files:
1 2 3 4 5 6 7 8 |
|
And then add code like this in your application class, being sure to invoke loadIconsForStage(stage)
during startup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Adapting a SWT app¶
SWT is a small JVM UI toolkit that maps directly to the operating system's native widgets. Here's a Gradle config (in Kotlin syntax) that uses the Conveyor plugin and sets up dependencies as appropriate. This sample also demonstrates how to write a bit of custom Gradle code to minimize repetition when specifying platform specific dependencies:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|