Class JLinkMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.jlink.AbstractJLinkMojo
-
- org.apache.maven.plugins.jlink.JLinkMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="jlink", requiresDependencyResolution=RUNTIME, defaultPhase=PACKAGE) public class JLinkMojo extends AbstractJLinkMojoThe JLink goal is intended to create a Java Run Time Image file based on https://openjdk.java.net/jeps/282, https://openjdk.java.net/jeps/220.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<org.apache.maven.model.Resource>additionalResourcesThese files are added to the image after calling jlink, but before creating the zip file.private java.util.List<java.lang.String>addModulesUsually this is not necessary, cause this is handled automatically by the given dependencies.private java.util.List<java.lang.String>addOptionsThese JVM arguments will be appended to thelib/modulesfile.
This parameter requires at least JDK 14.private booleanattachControls whether the plugin tries to attach the resulting artifact to the project.private booleanbindServicesAdd the option--bind-servicesor not.private java.io.FilebuildDirectoryprivate java.lang.StringclassifierClassifier to add to the artifact generated.private java.lang.StringcompressHere you can define the compression of the resources being used.private java.lang.StringdisablePluginYou can disable a plugin by using this option.private java.lang.StringendianThe byte order of the generated Java Run Time image.private java.lang.StringfinalNameName of the generated ZIP file in thetargetdirectory.private booleanignoreSigningInformation--ignore-signing-informationprivate java.util.List<java.lang.String>includeLocalesIncludes the list of locales where langtag is a BCP 47 language tag.private java.util.Map<java.lang.String,java.lang.String>jdkToolchainSpecify the requirements for this jdk toolchain.private java.lang.StringlauncherShould the plugin generate a launcher script by means of jlink? The command line equivalent is:--launcher <name>=<module>[/<mainclass>].private java.util.List<java.lang.String>launchersSpecify one or more launchers for jlink.private java.util.List<java.lang.String>limitModulesLimit the universe of observable modules.private org.codehaus.plexus.languages.java.jpms.LocationManagerlocationManagerprivate org.apache.maven.shared.filtering.MavenResourcesFilteringmavenResourcesFilteringprivate java.util.List<java.lang.String>modulePathsInclude additional paths on the--module-pathoption.private booleannoHeaderFilesThis will omit anincludesdirectory from the resulting Java Run Time Image.private booleannoManPagesThis will omit themandirectory from the resulting Java Run Time Image.private java.io.FileoutputDirectoryprivate java.io.FileoutputDirectoryImageThe output directory for the resulting Run Time Image.private java.lang.StringoutputTimestampTimestamp 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 java.lang.StringpluginModulePathDefine the plugin module path to be used.private org.apache.maven.project.MavenProjectHelperprojectHelperConvenience interface for plugins to add or replace artifacts and resources on projects.private java.io.FilesourceJdkModulesSet the JDK location to create a Java custom runtime image.private booleanstripDebugThis is intended to strip debug information out.private java.util.List<java.lang.String>suggestProvidersSuggest providers that implement the given service types from the module path.private booleanverboseThis will turn on verbose mode.private org.codehaus.plexus.archiver.zip.ZipArchiverzipArchiverThe JAR archiver needed for archiving the environments.private java.lang.StringzipDirPrefixAdd directory prefix to all of zip entries in top level files/directories.
-
Constructor Summary
Constructors Constructor Description JLinkMojo(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidattachArtifactUnlessDisabled(java.io.File artifactFile)protected java.util.List<java.lang.String>createJlinkArgs(java.util.Collection<java.lang.String> pathsOfModules, java.util.Collection<java.lang.String> modulesToAdd)private java.io.FilecreateZipArchiveFromImage(java.io.File outputDirectory, java.io.File outputDirectoryImage)voidexecute()private voidfailIfParametersAreNotInTheirValidValueRanges()protected java.lang.StringgetClassifier()Overload this to produce a zip with another classifier, for example a jlink-zip.(package private) java.util.List<java.io.File>getCompileClasspathElements(org.apache.maven.project.MavenProject project)Gets the compile classpath elements while filtering out artifacts that should be skipped.(package private) java.util.Map<java.lang.String,java.io.File>getModulePathElements()private static java.io.FilegetZipFile(java.io.File basedir, java.lang.String finalName, java.lang.String classifier)Returns the archive file to generate, based on an optional classifier.private booleanhasClassifier()private static booleanhasClassifier(java.lang.String classifier)private booleanhasIncludeLocales()private booleanhasLimitModules()private booleanhasSuggestProviders()private voidifOutputDirectoryExistsDelteIt()private booleanprojectHasAlreadySetAnArtifact()private voidrequireJdk14()private voidsetOutputDirectoryImage()Use 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 org.apache.maven.plugins.jlink.AbstractJLinkMojo
convertSeparatedModulePathToPlatformSeparatedModulePath, getJlinkExecutor, getProject, getSession, getToolchain
-
-
-
-
Field Detail
-
jdkToolchain
@Parameter private java.util.Map<java.lang.String,java.lang.String> jdkToolchain
Specify the requirements for this jdk toolchain. This overrules the toolchain selected by the maven-toolchain-plugin.
note: requires at least Maven 3.3.1.
-
stripDebug
@Parameter(defaultValue="false") private boolean stripDebug
This is intended to strip debug information out. The command line equivalent ofjlinkis:-G, --strip-debugstrip debug information.
-
compress
@Parameter private java.lang.String 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
@Parameter private java.lang.String 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
@Parameter private java.util.List<java.lang.String> launchers
Specify one or more launchers for jlink. The command line equivalent is:--launcher <name>=<module>[/<mainclass>]. The valid values are a list of<name>=<module>[/<mainclass>]terms, separated by commas.
-
addOptions
@Parameter private java.util.List<java.lang.String> 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
@Parameter private java.util.List<java.lang.String> 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
@Parameter private java.util.List<java.lang.String> 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
@Parameter private java.lang.String 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 java.io.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 java.io.File buildDirectory
-
outputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) private java.io.File outputDirectory
-
endian
@Parameter private java.lang.String 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
@Parameter private java.util.List<java.lang.String> modulePaths
Include additional paths on the--module-pathoption. Project dependencies and JDK modules are automatically added.
-
bindServices
@Parameter(defaultValue="false") private boolean bindServices
Add the option--bind-servicesor not.
-
disablePlugin
@Parameter private java.lang.String 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 noHeaderFiles
This 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 noManPages
This will omit themandirectory from the resulting Java Run Time Image. The JLink command line equivalent is:--no-man-pages
-
suggestProviders
@Parameter private java.util.List<java.lang.String> 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
@Parameter private java.util.List<java.lang.String> 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 verbose
This will turn on verbose mode. The jlink command line equivalent is:--verbose
-
sourceJdkModules
@Parameter private java.io.File sourceJdkModules
Set the JDK location to create a Java custom runtime image.
-
attach
@Parameter(defaultValue="true") private boolean attach
Controls whether the plugin tries to attach the resulting artifact to the project.- Since:
- 3.2.1
-
classifier
@Parameter private java.lang.String 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
@Parameter(defaultValue="${project.build.finalName}", readonly=true) private java.lang.String finalNameName of the generated ZIP file in thetargetdirectory. This will not change the name of the installed/deployed file.
-
outputTimestamp
@Parameter(defaultValue="${project.build.outputTimestamp}") private java.lang.String outputTimestampTimestamp 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
@Parameter private java.util.List<org.apache.maven.model.Resource> additionalResources
These files are added to the image after calling jlink, but before creating the zip file.- Since:
- 3.2.0
-
zipDirPrefix
@Parameter(defaultValue="") private java.lang.String 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 projectHelper
Convenience 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 zipArchiver
The JAR archiver needed for archiving the environments.
-
-
Constructor Detail
-
JLinkMojo
@Inject public JLinkMojo(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 Detail
-
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
java.util.List<java.io.File> getCompileClasspathElements(org.apache.maven.project.MavenProject project)
Gets the compile classpath elements while filtering out artifacts that should be skipped.- Parameters:
project- the Maven project- Returns:
- list of files that should be included in the classpath
-
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
java.util.Map<java.lang.String,java.io.File> getModulePathElements() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
projectHasAlreadySetAnArtifact
private boolean projectHasAlreadySetAnArtifact()
-
hasClassifier
private boolean hasClassifier()
- Returns:
- true when the classifier is not
nulland not empty
-
createZipArchiveFromImage
private java.io.File createZipArchiveFromImage(java.io.File outputDirectory, java.io.File outputDirectoryImage) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
attachArtifactUnlessDisabled
private void attachArtifactUnlessDisabled(java.io.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 java.util.List<java.lang.String> createJlinkArgs(java.util.Collection<java.lang.String> pathsOfModules, java.util.Collection<java.lang.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
protected java.lang.String getClassifier()
Overload this to produce a zip with another classifier, for example a jlink-zip.- Specified by:
getClassifierin classAbstractJLinkMojo- Returns:
- get the classifier
-
getZipFile
private static java.io.File getZipFile(java.io.File basedir, java.lang.String finalName, java.lang.String classifier)Returns the archive file to generate, based on an optional classifier.- Parameters:
basedir- the output directoryfinalName- the name of the zip fileclassifier- an optional classifier- Returns:
- the file to generate
-
hasClassifier
private static boolean hasClassifier(java.lang.String classifier)
-
-