2024-11-03 23:37:21 +01:00
|
|
|
# JLink Gradle plugin
|
|
|
|
|
|
|
|
This project defines a Gradle plugin that enable the use of
|
2024-11-07 17:48:36 +01:00
|
|
|
[jmod](https://docs.oracle.com/en/java/javase/21/docs/specs/man/jmod.html),
|
|
|
|
[jdeps](https://docs.oracle.com/en/java/javase/21/docs/specs/man/jdeps.html),
|
|
|
|
[jlink](ttps://docs.oracle.com/en/java/javase/21/docs/specs/man/jlink.html) and
|
|
|
|
[jpackage](ttps://docs.oracle.com/en/java/javase/21/docs/specs/man/jpackage.html) and
|
|
|
|
in Gradle builds on Linux.
|
|
|
|
|
2024-11-03 23:37:21 +01:00
|
|
|
In general, the plugin enables developers to create Java Runtimes with jlink.
|
|
|
|
It uses the java toolchain to locate the `jlink` executable and creates
|
|
|
|
a java runtime for your module path based Java application. This
|
|
|
|
modularization allows small, secure and tailored application distributions.
|
|
|
|
|
2024-11-07 17:48:36 +01:00
|
|
|
## Plugin usage
|
2024-11-03 23:37:21 +01:00
|
|
|
|
|
|
|
This Gradle plugin integrates with the [Gradle Java Library plugin](https://docs.gradle.org/current/userguide/java_library_plugin.html)
|
2024-11-07 17:48:36 +01:00
|
|
|
to create distributions automatically using a modular runtime rather than a user provided JDK runtime.
|
|
|
|
|
|
|
|
For this, it runs `jmod`, `jdeps`, `jlink` or `jpackage` in order to check and very module
|
|
|
|
dependencies on the Gradle runtime dependencies in an automatic way with minimum parameters to specify
|
|
|
|
|
|
|
|
`jmod` downloads all runtime depency jars and transforms them into the jmod file specification,
|
|
|
|
so `jdeps`
|
|
|
|
|
|
|
|
`jlink` creates a directory with a modular runtime (which can be passed to container builds)
|
|
|
|
while `jpackage` relies on Linux packaging tools to create an `RPM` or `DEB` package for
|
|
|
|
distribution.
|
2024-11-03 23:37:21 +01:00
|
|
|
|
2024-11-07 17:48:36 +01:00
|
|
|
Here is a minimal example to build a
|
2024-11-03 23:37:21 +01:00
|
|
|
|
|
|
|
```groovy
|
|
|
|
plugins {
|
|
|
|
id 'org.xbib.gradle.plugin.jlink' version "8.8.0"
|
|
|
|
}
|
|
|
|
|
|
|
|
java {
|
|
|
|
toolchain {
|
|
|
|
languageVersion.set(JavaLanguageVersion.of(21))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jlink {
|
|
|
|
modules.set(List.of("org.example.app"))
|
|
|
|
launcher.set("app=org.example.app/org.example.app.Main")
|
|
|
|
stripDebug.set(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
In addition, the plugin configures a `jmod` task to download the dependent artifacts on the
|
|
|
|
runtime class path and create jmod files for the `jlink` task. Also, a `jdeps` task is automatically
|
|
|
|
configured to show the dependent modules.
|
|
|
|
|
|
|
|
The plugin is currently only available under Linux.
|