JPackage Gradle Plugin

June 27, 2026 ยท View on GitHub

Gradle plugin for jpackage tool.

License Gradle Plugin Portal Gradle JDK

Finding jpackage

Plugin searches for jpackage executable using the following priority list:

  1. Configured toolchain

  2. java.home system property.

Though rarely required it is possible to override toolchain for particular jpackage task:

javaLauncher = javaToolchains.launcherFor {
    languageVersion = JavaLanguageVersion.of(21)
}

Configuration

There are generic jpackage parameters as well as OS-specific parameters for OS X, Linux, Windows. OS-specific parameters are processed when build is done on the corresponding OS.

If some generic parameters should have different values based on OS then they should be placed into configuration blocks:

  • windows
  • mac
  • linux

Example:

// Windows specific parameters will be processed only during Windows build
winMenu = true
winDirChooser = true

mac {
    // Generic parameter value for OS X build
    icon = layout.projectDirectory.file("icons/icons.icns")
}

windows {
    // Generic parameter value for Windows build
    icon = layout.projectDirectory.file("icons/icons.ico")
}

Parameters

ParameterTypeJPackage ArgumentMin VersionMax Version
Generic
aboutUrlProperty<String>--about-url <url>17*
addModulesListProperty<String>--add-modules <module>[,<module>]14*
appDescriptionProperty<String>--description <description string>14*
appContentConfigurableFileCollection--app-content additional-content[,additional-content...]18*
appImageProperty<String>--app-image <name>14*
appNameProperty<String>--name <name>14*
appVersionProperty<String>--app-version <version>14*
argumentsListProperty<String>--arguments <main class arguments>14*
copyrightProperty<String>--copyright <copyright string>14*
destinationDirectoryProperty--dest <destination path>14*
fileAssociationsConfigurableFileCollection--file-associations <file association property file>14*
iconRegularFileProperty--icon <icon file path>14*
inputDirectoryProperty--input <input path>14*
installDirProperty<String>--install-dir <file path>14*
javaOptionsListProperty<String>--java-options <options>14*
jLinkProperty<JLink>--jlink-options <options>16*
jLinkOptionsListProperty<String>--jlink-options <options>16*
launchersListProperty<Launcher>--add-launcher <name>=<property file>14*
launcherAsServiceProperty<Boolean>--launcher-as-service19*
licenseFileRegularFileProperty--license-file <license file path>14*
mainClassProperty<String>--main-class <class name>14*
mainJarProperty<String>--main-jar <main jar file>14*
moduleProperty<String>--module <module name>[/<main class>]14*
modulePathsConfigurableFileCollection--module-path <module path>14*
resourceDirDirectoryProperty--resource-dir <resource dir path>14*
runtimeImageDirectoryProperty--runtime-image <file path>14*
tempDirectoryProperty--temp <temp dir path>14*
typeProperty<ImageType>--type <type>14*
vendorProperty<String>--vendor <vendor string>14*
verboseProperty<Boolean>--verbose14*
Windows
winConsoleProperty<Boolean>--win-console14*
winDirChooserProperty<Boolean>--win-dir-chooser14*
winHelpUrlProperty<String>--win-help-url <url>17*
winMenuProperty<Boolean>--win-menu14*
winMenuGroupProperty<String>--win-menu-group <menu group name>14*
winPerUserInstallProperty<Boolean>--win-per-user-install14*
winShortcutProperty<Boolean>--win-shortcut14*
winShortcutPromptProperty<Boolean>--win-shortcut-prompt17*
winUpdateUrlProperty<String>--win-update-url <url>17*
winUpgradeUuidProperty<String>--win-upgrade-uuid <id string>14*
OS X
macAppCategoryProperty<String>--mac-app-category <category string>17*
macAppStoreProperty<Boolean>--mac-app-store17*
macBundleSigningPrefixProperty<String>--mac-bundle-signing-prefix <prefix string>1416
macDmgContentConfigurableFileCollection--mac-dmg-content additional-content[,additional-content...]18*
macEntitlementsRegularFileProperty--mac-entitlements <file path>17*
macPackageIdentifierProperty<String>--mac-package-identifier <ID string>14*
macPackageNameProperty<String>--mac-package-name <name string>14*
macPackageSigningPrefixProperty<String>--mac-package-signing-prefix <prefix string>17*
macSignProperty<Boolean>--mac-sign14*
macSigningKeychainProperty<String>--mac-signing-keychain <keychain name>14*
macSigningKeyUserNameProperty<String>--mac-signing-key-user-name <team name>14*
Linux
linuxAppCategoryProperty<String>--linux-app-category <category value>14*
linuxAppReleaseProperty<String>--linux-app-release <release value>14*
linuxDebMaintainerProperty<String>--linux-deb-maintainer <email address>14*
linuxMenuGroupProperty<String>--linux-menu-group <menu-group-name>14*
linuxPackageNameProperty<String>--linux-package-name <package name>14*
linuxPackageDepsProperty<String>--linux-package-deps <package-dep-string>14*
linuxRpmLicenseTypeProperty<String>--linux-rpm-license-type <type string>14*
linuxShortcutProperty<Boolean>--linux-shortcut14*

Since version 1.7.0 the plugin does not check if parameter is applicable to jpackage tool version. Users are advised to consult the corresponding User's Guide.

Image Type

Plugin ValueJPackage Type
DEFAULTDefault image type, OS specific
APP_IMAGEapp-image
DMGdmg
PKGpkg
EXEexe
MSImsi
RPMrpm
DEBdeb

Launchers

Launchers are defines using class Launcher:

launchers = listOf(
    Launcher("launcher_1", layout.projectDirectory.file("launcher_1.properties").asFile),
    Launcher("launcher_2", layout.projectDirectory.file("launcher_2.properties").asFile)
)

Destination Directory

jpackage utility fails if output directory already exists. At the same time gradle always creates plugin output directory.

In order to work around this behaviour plugin always tries to delete directory specified by destination before launching jpackage.

For safety reasons destination must point to the location inside ${layout.buildDirectory}.

Example:

destination = layout.buildDirectory.dir("dist")

Default Command-Line Arguments

Default command line arguments are passed to the main class when the application is started without providing arguments.

Example:

arguments = listOf(
    "SomeArgument",
    "Argument with spaces",
    "Argument with \"quotes\""
)

JVM Options

Options that are passed to the JVM when the application is started.

Example:

javaOptions = listOf(
    "-Xms2m",
    "-Xmx10m"
)

Options that are passed to underlying jlink call.

Example:

jLinkOptions = listOf(
    "--strip-native-commands",
    "--strip-debug"
)

Another way is to use jLink property of class JLink:

FieldTypejlink Option
bindServicesboolean--bind-services
noHeaderFilesboolean--no-header-files
noManPagesboolean--no-man-pages
stripDebugboolean--strip-debug
stripNativeCommandsboolean--strip-native-commands
generateCdsArchiveboolean--generate-cds-archive

Example:

jLink = JLink().apply {
    stripNativeCommands = true
    noHeaderFiles = true
    noManPages = true
    stripDebug = true
}

Both ways can be used together if required.

jpackage Environment Variables

Optionally environment variables can be passed to jpackage executable process.

Example:

jpackageEnvironment = mapOf(
    "GRADLE_DIR" to project.projectDir.absolutePath,
    "BUILD_DIR" to project.buildDir.absolutePath
)

null values as well as null or empty keys are ignored.

Logging

Plugin uses LogLevel.INFO to print various information about toolchain, jpackage parameters, etc. Use gradle option --info to check this output.

Dry Run Mode

To execute plugin tasks in dry run mode without calling jpackage set propertyjpackage.dryRun to true.

Example:

$ ./gradlew clean build jpackage --info -Djpackage.dryRun=true

Configuration Cache

This plugin should be compatible with Gradle configuration cache.

Examples

References

Packaging Tool User's Guide