Class JLinkMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<org.apache.maven.model.Resource> These files are added to the image after calling jlink, but before creating the zip file.Usually this is not necessary, cause this is handled automatically by the given dependencies.These JVM arguments will be appended to thelib/modulesfile.
This parameter requires at least JDK 14.private booleanControls whether the plugin tries to attach the resulting artifact to the project.private booleanAdd the option--bind-servicesor not.private Fileprivate StringClassifier to add to the artifact generated.private StringHere you can define the compression of the resources being used.private StringYou can disable a plugin by using this option.private StringThe byte order of the generated Java Run Time image.private StringName of the generated ZIP file in thetargetdirectory.private boolean--ignore-signing-informationIncludes the list of locales where langtag is a BCP 47 language tag.Specify the requirements for this jdk toolchain.private StringShould the plugin generate a launcher script by means of jlink? The command line equivalent is:--launcher <name>=<module>[/<mainclass>].Specify one or more launchers for jlink.Limit the universe of observable modules.private final org.codehaus.plexus.languages.java.jpms.LocationManagerprivate final org.apache.maven.shared.filtering.MavenResourcesFilteringInclude additional paths on the--module-pathoption.private booleanThis will omit anincludesdirectory from the resulting Java Run Time Image.private booleanThis will omit themandirectory from the resulting Java Run Time Image.private Fileprivate FileThe output directory for the resulting Run Time Image.private StringTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).private StringDefine the plugin module path to be used.private final org.apache.maven.project.MavenProjectHelperConvenience interface for plugins to add or replace artifacts and resources on projects.private FileSet the JDK location to create a Java custom runtime image.private booleanThis is intended to strip debug information out.Suggest providers that implement the given service types from the module path.private booleanThis will turn on verbose mode.private final org.codehaus.plexus.archiver.zip.ZipArchiverThe JAR archiver needed for archiving the environments.private StringAdd directory prefix to all of zip entries in top level files/directories.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
ConstructorsConstructorDescriptionJLinkMojo(org.apache.maven.project.MavenProjectHelper projectHelper, org.apache.maven.toolchain.ToolchainManager toolchainManager, org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering, org.codehaus.plexus.languages.java.jpms.LocationManager locationManager) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidattachArtifactUnlessDisabled(File artifactFile) createJlinkArgs(Collection<String> pathsOfModules, Collection<String> modulesToAdd) private FilecreateZipArchiveFromImage(File outputDirectory, File outputDirectoryImage) voidexecute()private voidprotected StringOverload this to produce a zip with another classifier, for example a jlink-zip.getCompileClasspathElements(org.apache.maven.project.MavenProject project) Gets the compile classpath elements while filtering out artifacts that should be skipped.private static FilegetZipFile(File basedir, String finalName, String classifier) Returns the archive file to generate, based on an optional classifier.private booleanprivate static booleanhasClassifier(String classifier) private booleanprivate booleanprivate booleanprivate voidprivate booleanprivate voidprivate voidUse a separate directory for each image.private booleanshouldSkip(org.apache.maven.artifact.Artifact artifact) Determines if an artifact should be skipped based on its properties.Methods inherited from class AbstractJLinkMojo
convertSeparatedModulePathToPlatformSeparatedModulePath, getJlinkExecutor, getProject, getSession, getToolchainMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
jdkToolchain
-
stripDebug
@Parameter(defaultValue="false") private boolean stripDebugThis is intended to strip debug information out. The command line equivalent ofjlinkis:-G, --strip-debugstrip debug information. -
compress
Here you can define the compression of the resources being used. The command line equivalent is:-c, --compress=<level>.The valid values for the level depend on the JDK:
For JDK 9+:
- 0: No compression. Equivalent to zip-0.
- 1: Constant String Sharing
- 2: Equivalent to zip-6.
For JDK 21+, those values are deprecated and to be removed in a future version. The supported values are:
zip-[0-9], wherezip-0provides no compression, andzip-9provides the best compression.
Default iszip-6. -
launcher
Should the plugin generate a launcher script by means of jlink? The command line equivalent is:--launcher <name>=<module>[/<mainclass>]. The valid values for the level are:<name>=<module>[/<mainclass>]. -
launchers
-
addOptions
These JVM arguments will be appended to thelib/modulesfile.
This parameter requires at least JDK 14.
The command line equivalent is:
jlink --add-options="...".Example:
<addOptions> <addOption>-Xmx256m</addOption> <addOption>--enable-preview</addOption> <addOption>-Dvar=value</addOption> </addOptions>Above example will result in
jlink --add-options="-Xmx256m" --enable-preview -Dvar=value". -
limitModules
Limit the universe of observable modules. The following gives an example of the configuration which can be used in thepom.xmlfile.<limitModules> <limitModule>mod1</limitModule> <limitModule>xyz</limitModule> . . </limitModules>This configuration is the equivalent of the command line option:--limit-modules <mod>[,<mod>...] -
addModules
Usually this is not necessary, cause this is handled automatically by the given dependencies.
By using the --add-modules you can define the root modules to be resolved. The configuration in
pom.xmlfile can look like this:<addModules> <addModule>mod1</addModule> <addModule>first</addModule> . . </addModules>
The command line equivalent for jlink is:--add-modules <mod>[,<mod>...]. -
pluginModulePath
Define the plugin module path to be used. There can be defined multiple entries separated by either;or:. The jlink command line equivalent is:--plugin-module-path <modulepath> -
outputDirectoryImage
@Parameter(defaultValue="${project.build.directory}/maven-jlink", required=true, readonly=true) private File outputDirectoryImageThe output directory for the resulting Run Time Image. The created Run Time Image is stored in non compressed form. This will later being packaged into azipfile.--output <path>The
classifieris appended as a subdirecty if it exists, otherwisedefaultwill be used as subdirectory. This ensures that multiple executions using classifiers will not overwrite the previous run’s image. -
buildDirectory
@Parameter(defaultValue="${project.build.directory}", required=true, readonly=true) private File buildDirectory -
outputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) private File outputDirectory -
endian
The byte order of the generated Java Run Time image.--endian <little|big>. If the endian is not given the default is:native. -
modulePaths
-
bindServices
@Parameter(defaultValue="false") private boolean bindServicesAdd the option--bind-servicesor not. -
disablePlugin
You can disable a plugin by using this option.--disable-plugin pluginName. -
ignoreSigningInformation
@Parameter(defaultValue="false") private boolean ignoreSigningInformation--ignore-signing-information -
noHeaderFiles
@Parameter(defaultValue="false") private boolean noHeaderFilesThis will omit anincludesdirectory from the resulting Java Run Time Image. The JLink command line equivalent is:--no-header-files -
noManPages
@Parameter(defaultValue="false") private boolean noManPagesThis will omit themandirectory from the resulting Java Run Time Image. The JLink command line equivalent is:--no-man-pages -
suggestProviders
Suggest providers that implement the given service types from the module path.<suggestProviders> <suggestProvider>name-a</suggestProvider> <suggestProvider>name-b</suggestProvider> . . </suggestProviders>
The jlink command linke equivalent:--suggest-providers [<name>,...] -
includeLocales
Includes the list of locales where langtag is a BCP 47 language tag.This option supports locale matching as defined in RFC 4647. Ensure that you add the module jdk.localedata when using this option.
The command line equivalent is:
--include-locales=en,ja,*-IN.<includeLocales> <includeLocale>en</includeLocale> <includeLocale>ja</includeLocale> <includeLocale>*-IN</includeLocale> . . </includeLocales>
-
verbose
@Parameter(defaultValue="false") private boolean verboseThis will turn on verbose mode. The jlink command line equivalent is:--verbose -
sourceJdkModules
Set the JDK location to create a Java custom runtime image. -
attach
@Parameter(defaultValue="true") private boolean attachControls whether the plugin tries to attach the resulting artifact to the project.- Since:
- 3.2.1
-
classifier
Classifier to add to the artifact generated. If given, the artifact will be attached as a supplemental artifact. If not given, this will create the main artifact which is the default behavior. If you try to do that a second time without using a classifier, the build will fail. -
finalName
Name of the generated ZIP file in thetargetdirectory. This will not change the name of the installed/deployed file. -
outputTimestamp
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.2.0
-
additionalResources
These files are added to the image after calling jlink, but before creating the zip file.- Since:
- 3.2.0
-
zipDirPrefix
Add directory prefix to all of zip entries in top level files/directories.For example, if this value is set to
prefix,bin/launcheris transformed toprefix/bin/launcher.Empty String is set by default. It means no prefix.
- Since:
- 3.2.1
-
projectHelper
private final org.apache.maven.project.MavenProjectHelper projectHelperConvenience interface for plugins to add or replace artifacts and resources on projects. -
mavenResourcesFiltering
private final org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering -
locationManager
private final org.codehaus.plexus.languages.java.jpms.LocationManager locationManager -
zipArchiver
private final org.codehaus.plexus.archiver.zip.ZipArchiver zipArchiverThe JAR archiver needed for archiving the environments.
-
-
Constructor Details
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
getCompileClasspathElements
-
shouldSkip
private boolean shouldSkip(org.apache.maven.artifact.Artifact artifact) Determines if an artifact should be skipped based on its properties. Currently, skips POM type artifacts, but can be extended for other cases.- Parameters:
artifact- the artifact to check- Returns:
- true if the artifact should be skipped, false otherwise
-
getModulePathElements
-
projectHasAlreadySetAnArtifact
private boolean projectHasAlreadySetAnArtifact() -
hasClassifier
private boolean hasClassifier()- Returns:
- true when the classifier is not
nulland not empty
-
createZipArchiveFromImage
-
attachArtifactUnlessDisabled
private void attachArtifactUnlessDisabled(File artifactFile) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
failIfParametersAreNotInTheirValidValueRanges
private void failIfParametersAreNotInTheirValidValueRanges() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
requireJdk14
private void requireJdk14() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
setOutputDirectoryImage
private void setOutputDirectoryImage()Use a separate directory for each image.Rationale: If a user creates multiple jlink artifacts using classifiers, the directories should not overwrite themselves for each execution.
-
ifOutputDirectoryExistsDelteIt
private void ifOutputDirectoryExistsDelteIt() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
createJlinkArgs
protected List<String> createJlinkArgs(Collection<String> pathsOfModules, Collection<String> modulesToAdd) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
hasIncludeLocales
private boolean hasIncludeLocales() -
hasSuggestProviders
private boolean hasSuggestProviders() -
hasLimitModules
private boolean hasLimitModules() -
getClassifier
Overload this to produce a zip with another classifier, for example a jlink-zip.- Specified by:
getClassifierin classAbstractJLinkMojo- Returns:
- get the classifier
-
getZipFile
-
hasClassifier
-