Class JLinkMojo

    • Field Summary

      Fields 
      Modifier and Type Field Description
      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.
      private java.util.List<java.lang.String> addModules
      Usually this is not necessary, cause this is handled automatically by the given dependencies.
      private java.util.List<java.lang.String> addOptions
      These JVM arguments will be appended to the lib/modules file.
      This parameter requires at least JDK 14.
      private boolean attach
      Controls whether the plugin tries to attach the resulting artifact to the project.
      private boolean bindServices
      Add the option --bind-services or not.
      private java.io.File buildDirectory  
      private java.lang.String classifier
      Classifier to add to the artifact generated.
      private java.lang.String compress
      Here you can define the compression of the resources being used.
      private java.lang.String disablePlugin
      You can disable a plugin by using this option.
      private java.lang.String endian
      The byte order of the generated Java Run Time image.
      private java.lang.String finalName
      Name of the generated ZIP file in the target directory.
      private boolean ignoreSigningInformation
      --ignore-signing-information
      private java.util.List<java.lang.String> includeLocales
      Includes the list of locales where langtag is a BCP 47 language tag.
      private java.util.Map<java.lang.String,​java.lang.String> jdkToolchain
      Specify the requirements for this jdk toolchain.
      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>].
      private java.util.List<java.lang.String> launchers
      Specify one or more launchers for jlink.
      private java.util.List<java.lang.String> limitModules
      Limit the universe of observable modules.
      private org.codehaus.plexus.languages.java.jpms.LocationManager locationManager  
      private org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering  
      private java.util.List<java.lang.String> modulePaths
      Include additional paths on the --module-path option.
      private boolean noHeaderFiles
      This will omit an includes directory from the resulting Java Run Time Image.
      private boolean noManPages
      This will omit the man directory from the resulting Java Run Time Image.
      private java.io.File outputDirectory  
      private java.io.File outputDirectoryImage
      The output directory for the resulting Run Time Image.
      private java.lang.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).
      private java.lang.String pluginModulePath
      Define the plugin module path to be used.
      private org.apache.maven.project.MavenProjectHelper projectHelper
      Convenience interface for plugins to add or replace artifacts and resources on projects.
      private java.io.File sourceJdkModules
      Set the JDK location to create a Java custom runtime image.
      private boolean stripDebug
      This is intended to strip debug information out.
      private java.util.List<java.lang.String> suggestProviders
      Suggest providers that implement the given service types from the module path.
      private boolean verbose
      This will turn on verbose mode.
      private org.codehaus.plexus.archiver.zip.ZipArchiver zipArchiver
      The JAR archiver needed for archiving the environments.
      private java.lang.String zipDirPrefix
      Add directory prefix to all of zip entries in top level files/directories.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • 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)  
    • 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 of jlink is: -G, --strip-debug strip 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], where zip-0 provides no compression, and zip-9 provides the best compression.
        Default is zip-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 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 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 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 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.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 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 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 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-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 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 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 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 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 java.lang.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 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/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 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.MojoExecutionException
        org.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 null and 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:
        getClassifier in class AbstractJLinkMojo
        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 directory
        finalName - the name of the zip file
        classifier - an optional classifier
        Returns:
        the file to generate
      • hasClassifier

        private static boolean hasClassifier​(java.lang.String classifier)