If you use jlink, you can create a JRE dedicated to the app, which is convenient for distribution. So I tried to find out how to use it with gradle.
For the time being, normally
gradle init --type=java-application
Make with.
The minimum requirement is to add the following line to the plugins item.
id 'org.beryx.jlink' version '2.22.0'
Now you can use gradle jlink.
Also, if you delete the dependencies that are included by default, the warning disappears. (It seems that module names ending with numbers should not be used)
In addition, depending on the version of JDK
The module name specified in 'application.mainModule' (null) has not the expected value
Is displayed. This is in the application item
mainModule ='module name'
It disappears if you write. (The module name is specified in module-info.java)
It is also possible to create a jlink item and set an option. For example, you can write as follows.
jlink {
options = ['--compress', '2', '--no-header-files', '--no-man-pages']
}
You can also create apps for multiple platforms with targetPlatform. In this case, prepare a JDK for each platform.
jlink {
targetPlatform("mac") {
jdkHome = "/usr/java/jdk-mac/Contents/Home"
}
targetPlatform("linux-x64") {
jdkHome = "/usr/java/jdk"
}
targetPlatform("windows-x64") {
jdkHome = "/usr/java/jdk-win"
}
options = ['--compress', '2', '--no-header-files', '--no-man-pages']
}
gradle build
Now you can jar without using jlink. When jlinking, do as follows.
gradle jlink
Now you have an image under the build directory, and the directory under it is your app. If targetPlatform is specified, a directory of \ <project name >-\ <target platform name > will be created and placed under it.
To execute the application, there is an execution script of \ <project name > in the bin directory, so you can execute it. (Bat file for Windows)
You can distribute the application by distributing the bin, conf, legal, and lib directories together. You can start it by copying it as it is and executing the bin executable file.
Recommended Posts