andrewinci/Insulator

View on GitHub
buildSrc/src/main/groovy/insulator.jpackage.gradle

Summary

Maintainability
Test Coverage
import org.gradle.internal.os.OperatingSystem

task dist(type: Copy) {
    group = 'distribution'
    dependsOn 'distZip'

    def zipFile = file("${buildDir}/distributions/${project.name}.zip")
    def outputDir = file("${buildDir}/distributions")

    from zipTree(zipFile)
    into outputDir
}

task packageApp(type: Exec) {
    group = 'jpackage'
    dependsOn 'dist'

    // build command
    def appVersion = "${System.getenv().get("RELEASE_VERSION") ?: "0.0.0"}"
    def command = ['jpackage', '--input', "./build/distributions/${project.name}/lib/", '--main-jar', "${project.name}.jar", '-d', '.',
                   '--name', 'Insulator', '--java-options', "'--enable-preview'", '--app-version', appVersion]

    // customization for each OS
    if (OperatingSystem.current().isWindows()) command.addAll('--icon', '../assets/icon.ico', '--win-dir-chooser', '--win-menu')
    else if (OperatingSystem.current().isMacOsX()) command.addAll('--icon', '../assets/icon.icns')
    else command.addAll('--icon', '../assets/icon.png', '--linux-shortcut')

    // run command
    commandLine(command)
}