Skip to main content

Gradle

JavaPackager supports Gradle 7 and newer, including Gradle 9. To bundle a customized JRE, build with a JDK 9 or newer.

Apply the plugin​

Apply the plugin in build.gradle:

plugins {
id 'io.github.javapackager' version '2.0.0'
}

No extra repositories are needed: the plugin is published on Maven Central, and Gradle finds it through the Gradle Plugin Portal, its default plugin repository. Check the latest version on Maven Central or in the releases.

The plugin applies the java plugin, and adds a package task and a javapackager extension to configure it.

Configure and package your app​

Configure the app in the javapackager extension:

javapackager {
mainClass = 'com.example.Main'
}

mainClass is the only mandatory property. Then run:

gradle package

The package task runs after build. The app and its installers are generated in build/. See generated artifacts for what you get, and which tools each installer needs.

With Gradle, bundleJre is true by default: a customized JRE with only the modules your app needs is bundled with it, so users don't need Java installed. Set bundleJre = false to leave it out.

note

The Maven plugin doesn't bundle a JRE by default (bundleJre is false there).

A fuller example​

javapackager {
// mandatory
mainClass = 'com.example.Main'
// optional
name = 'MyApp'
displayName = 'My App'
bundleJre = true
generateInstaller = true
administratorRequired = false
platform = 'auto'
vmArgs = [ '-Xmx512m' ]
additionalResources = [ file('README.md'), file('config') ]
linuxConfig {
...
}
macConfig {
...
}
winConfig {
...
}
}

Every property is described in the configuration reference, and the platform-specific ones in GNU/Linux, macOS and Windows.

Your own tasks​

To package the app more than once (several platforms, with and without JRE...), register your own tasks of type PackageTask. They take every property from the javapackager extension, and the ones you set in the task override them:

tasks.register('packageForWindows', io.github.javapackager.gradle.PackageTask) {
dependsOn build
platform = 'windows'
createZipball = true
}
note

In a task, the app's name property is appName, because name is the task's own name.

See several executions and platforms and the Gradle samples.

Properties taken from your project​

PropertyTaken from
namethe project name
versionthe project version
descriptionthe project description, as it is when the plugin is applied (set description in javapackager if you set the project's later)
licenseFilea LICENSE file in the root project folder
jreMinVersionthe Java targetCompatibility (for Launch4j on Windows)
packagingJdkthe Java toolchain, if the project defines one

mainClass is not taken from the application plugin: set it in javapackager.