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 AbstractJLinkMojo
The 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 Details

    • jdkToolchain

      @Parameter private Map<String,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 of jlink is: -G, --strip-debug strip debug information.
    • compress

      @Parameter private 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], where zip-0 provides no compression, and zip-9 provides the best compression.
      Default is zip-6.

    • launcher

      @Parameter private 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 List<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 List<String> addOptions
      These JVM arguments will be appended to the lib/modules file.
      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 List<String> limitModules
      Limit the universe of observable modules. The following gives an example of the configuration which can be used in the pom.xml file.
         <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 List<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.xml file 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 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 File outputDirectoryImage
      The 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 a zip file. --output <path>

      The classifier is appended as a subdirecty if it exists, otherwise default will 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

      @Parameter private 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 List<String> modulePaths
      Include additional paths on the --module-path option. Project dependencies and JDK modules are automatically added.
    • bindServices

      @Parameter(defaultValue="false") private boolean bindServices
      Add the option --bind-services or not.
    • disablePlugin

      @Parameter private 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 an includes directory 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 the man directory from the resulting Java Run Time Image. The JLink command line equivalent is: --no-man-pages
    • suggestProviders

      @Parameter private List<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 List<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 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 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 String finalName
      Name of the generated ZIP file in the target directory. This will not change the name of the installed/deployed file.
    • outputTimestamp

      @Parameter(defaultValue="${project.build.outputTimestamp}") private String outputTimestamp
      Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
      Since:
      3.2.0
    • additionalResources

      @Parameter private 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 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/launcher is transformed to prefix/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 Details

    • 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 Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • getCompileClasspathElements

      List<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

      Map<String,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 null and not empty
    • createZipArchiveFromImage

      private File createZipArchiveFromImage(File outputDirectory, File outputDirectoryImage) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • 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

      protected String getClassifier()
      Overload this to produce a zip with another classifier, for example a jlink-zip.
      Specified by:
      getClassifier in class AbstractJLinkMojo
      Returns:
      get the classifier
    • getZipFile

      private static File getZipFile(File basedir, String finalName, String classifier)
      Returns the archive file to generate, based on an optional classifier.
      Parameters:
      basedir - the output directory
      finalName - the name of the zip file
      classifier - an optional classifier
      Returns:
      the file to generate
    • hasClassifier

      private static boolean hasClassifier(String classifier)