javamacosgradlejpackage

How to create an installer for macbook from a gradle project, using gradle build file with jpackage


this is the first time I am using Java outside the context of university, where you just send a zip file, now I need to create an installer for a client, and I need to compile this simple priject https://github.com/dolev146/installer-gradle-jpackage

I created it with gradle init, pressed all the default, except the build for groovy, instead of kotlin.

what I need to know is how can I create an installer for MacBook? dmg/pkg installer?

I tried adding this to the gradle.build

task createInstaller(type: Exec) {
    // Ensure the application is built before creating the installer
    dependsOn 'build'

    doFirst {
        // Create a custom runtime image with jlink
        exec {
            commandLine 'jlink', '--module-path', 'build/libs:deps', '--add-modules', 'your.module.name', '--output', 'app-image', '--compress', '2', '--no-header-files', '--no-man-pages'
        }
        // Use jpackage to create the installer
        exec {
            commandLine 'jpackage', '--type', 'pkg', '--input', 'build/libs', '--dest', 'build/installer', '--name', 'YourAppName', '--main-jar', 'yourapp.jar', '--main-class', 'your.main.Class', '--runtime-image', 'app-image'
        }
    }
}

then I run

./gradlew createInstaller

and it gave me this error

Error: Module your.module.name not found

how can I know what is my module name?

this is my first project with gradle

link to github project https://github.com/dolev146/installer-gradle-jpackage


Solution

  • Solution:

    1. run gradle build

    2. locate the directory with app.jar file and navigate to it with the terminal

    3. then pase this snippet

    jpackage --input ./ --name appName --main-jar app.jar --type dmp --main-class org.example.App
    

    where ./ is the path to the app.jar and --main-class org.example.App can be found in the grade.settings file