On Windows my createPackage task fails running the tool jpackage.
Running Gradle with Java 11. The jpackage command is with JDK-13. The runtime used with jpackage is created with JDK11 jlink.
I found the cygpath method in openjdk-jfx build.gradle on GitHub. Otherwise it would fail mixing both Linux and Windows path seperators.
task createPackage(type: Exec) {
dependsOn createRuntime
dependsOn installDist
def outputDir = cygpath("${buildDir}/native")
outputs.dir(outputDir)
def inputDir = cygpath(new File(installDist.outputs.files.singleFile, 'lib').path)
inputs.dir(inputDir)
def resourceDir = cygpath("${buildDir}/package")
def runtimeImageDir = cygpath(createRuntime.outputs.files.singleFile.path)
def installer = ""
if (OperatingSystem.current().isLinux()) {
installer = "rpm"
} else if (OperatingSystem.current().isWindows()) {
installer = "exe"
} else if (OperatingSystem.current().isMacOsX()) {
installer = "pkg"
}
commandLine 'jpackage', 'create-installer',
'--verbose',
'--overwrite',
'--installer-type', "${installer}",
'--name', project.name,
'--app-version', applicationVersion,
'--main-jar', jar.archiveName,
'--jvm-args', '-Xmx2g,-Djdk.gtk.version=2',
'--arguments', '--laf=nimbus',
'--runtime-image', runtimeImageDir,
'--resource-dir', resourceDir,
'--input', inputDir,
'--output', outputDir
}
The output:
Custom actions are attached to task ':createPackage'.
Starting process 'command 'jpackage''. Working directory: C:\cygwin64\home\build\workspace\application Command: jpackage create-installer --verbose --overwrite --installer-type exe --name application --app-version 3.0 --main-jar application-3.0-SNAPSHOT.jar --jvm-args -Xmx2g,-Djdk.gtk.version=2 --arguments --laf=nimbus --runtime-image C:/cygwin64/home/build/workspace/application/build/runtime --resource-dir C:/cygwin64/home/build/workspace/application/build/package --input C:/cygwin64/home/build/workspace/application/build/install/application/lib --output C:/cygwin64/home/build/workspace/application/build/native
:createPackage (Thread[Daemon worker Thread 5,5,main]) completed. Took 1.009 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':createPackage'.
> A problem occurred starting process 'command 'jpackage''
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':createPackage'.
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'jpackage''
at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:232)
at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:209)
at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:356)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
... 3 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'jpackage'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.startProcess(ExecHandleRunner.java:97)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:70)
... 4 more
Caused by: java.io.IOException: Cannot run program "jpackage" (in directory "C:\cygwin64\home\build\workspace\application"): CreateProcess error=2, The system cannot find the file specified
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 8 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
... 9 more
I am not sure what directory it complains about, but the one in the stack trace does exist.
If I take this command exactly and run manually it works fine:
jpackage create-installer --verbose --overwrite --installer-type exe --name application --app-version 3.0 --main-jar application-3.0-SNAPSHOT.jar --jvm-args -Xmx2g,-Djdk.gtk.version=2 --arguments --laf=nimbus --runtime-image C:/cygwin64/home/build/workspace/application/build/runtime --resource-dir C:/cygwin64/home/build/workspace/application/build/package --input C:/cygwin64/home/build/workspace/application/build/install/application/lib --output C:/cygwin64/home/build/workspace/application/build/native
It seems the problem is that Gradle on Windows cannot find the executable jpackage. I get same error when I change the executable name
Caused by: java.io.IOException: Cannot run program "jpackaga" (in directory "C:\cygwin64\home\build\workspace\application"): CreateProcess error=2, The system cannot find the file specified
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 8 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
... 9 more
The jpackage executable is on the path in cygwin, but not on Windows Path.
I cannot put the JDK13 on Windows Path, because then it would preceed the JAVA_HOME JDK11 path.