packaging-gradle-plugin

Start making native distributions for your JAR

View the Project on GitHub hendraanggrian/packaging-gradle-plugin

Travis CI Maven Central OpenJDK

Packaging Gradle Plugin

Gradle plugin that wraps JARs into native bundle for Windows, macOS, and Linux.

Version Method
0.1 packr
0.2+ jpackage

Download

Using plugins DSL:

plugins {
    id('com.hendraanggrian.packaging') version "$version"
}

Using legacy plugin application:

buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath("com.hendraanggrian:packaging-gradle-plugin:$version")
    }
}

apply plugin: 'com.hendraanggrian.packaging'

Usage

Below are example configuration for Windows64 and MacOS distributions. Note that properties of distribution configuration may override extension configuration.

packaging {
    executable.set('example')
    classpath.set(new File('path/to/jar'))
    mainClass.set('com.example.App')
    vmArgs.addAll('-Xmx1G')
    resources.addAll(new File('image.jpg'), new File('path/to/other.jpg'))
    minimizeJre.set('hard')
    outputDirectory.set(new File('my/folder'))
    verbose.set(true)
    autoOpen.set(true)
}

tasks {
    packWindows64 {
        executable.set('example64')
        vmArgs.add('-Xdebug')
        appName.set('Example Windows 64-bit')
        jdk.set('path/to/windows_64_jdk')
    }
    packMacOS {
        name.set('Example.app')
        jdk.set('path/to/mac_jdk')
        icon.set(new File('path/to/mac_icon.icns'))
        bundleId.set('com.example.app')
    }
}

Using Application Plugin

For easier setup, also use application plugin to distribute classpath with installDist command.

apply plugin: 'application'
apply plugin: 'com.hendraanggrian.packaging'

application {
    applicationName = 'My App'
    mainClass.set('com.example.App')
}