Skip to content

Add support for JLink plugins #602

@Til7701

Description

@Til7701

New feature, improvement proposal

JLink has a lot of plugins. Some of them have been added to this Maven plugin (#513 #539). However not all plugins are supported jet.

As of JDK 24 some more plugins have been documented: https://docs.oracle.com/en/java/javase/24/docs/specs/man/jlink.html

  • --order-resources=pattern-list
  • --generate-cds-archive

There are also some more plugins which are not documented and thus subject to change. You can list them with jlink --list-plugins. The Oracle OpenJDK 24 gives me the following list.

List of available plugins:
  --add-options <options>   Prepend the specified <options> string, which may
                            include whitespace, before any other options when
                            invoking the virtual machine in the resulting image.
  --compress <compress>     Compression to use in compressing resources:
                            Accepted values are:
                            zip-[0-9], where zip-0 provides no compression,
                            and zip-9 provides the best compression.
                            Default is zip-6.
  --dedup-legal-notices [error-if-not-same-content]
                            De-duplicate all legal notices.
                            If error-if-not-same-content is specified then
                            it will be an error if two files of the same
                            filename are different.
  --exclude-files <pattern-list>
                            Specify files to exclude.
                            e.g.: **.java,glob:/java.base/lib/client/**
  --exclude-jmod-section <section-name>
                            Specify a JMOD section to exclude.
                            Where <section-name> is "man" or "headers".
  --exclude-resources <pattern-list>
                            Specify resources to exclude.
                            e.g.: **.jcov,glob:**/META-INF/**
  --generate-cds-archive    Generate CDS archive if the runtime image supports
                            the CDS feature.
  --generate-jli-classes @filename
                            Specify a file listing the java.lang.invoke
                            classes to pre-generate. By default, this plugin
                            may use a builtin list of classes to pre-generate.
                            If this plugin runs on a different runtime version
                            than the image being created then code generation
                            will be disabled by default to guarantee
                            correctness add ignore-version=true
                            to override this.
  --include-locales <langtag>[,<langtag>]*
                            BCP 47 language tags separated by a comma,
                            allowing
                            locale matching defined in RFC 4647.
                            e.g.: en,ja,*-IN
  --order-resources <pattern-list>
                            Order resources.
                            e.g.: **/module-info.class,@classlist,
                            /java.base/java/lang/**
  --release-info <file>|add:<key1>=<value1>:<key2>=<value2>:...|del:<key list>
                            <file> option is to load release properties from
                            the supplied file.
                            add: is to add properties to the release file.
                            Any number of <key>=<value> pairs can be passed.
                            del: is to delete the list of keys in release file.
  --save-jlink-argfiles <filenames>
                            Save the specified argument files that contain
                            the arguments to be prepended to the execution of
                            jlink in the output image. <filenames> is a
                            : (; on Windows) separated list of command-line argument files.
  --strip-debug             Strip debug information from the output image
  --strip-java-debug-attributes
                            Strip Java debug attributes from
                            classes in the output image
  --strip-native-commands   Exclude native commands (such as java/java.exe)
                            from the image.
  --system-modules [batch-size=<N>]
                            The batch size specifies the maximum number of modules
                            be handled in one method to workaround if the generated
                            bytecode exceeds the method size limit. The default
                            batch size is 75.
  --vendor-bug-url <vendor-bug-url>
                            Override the vendor bug URL baked into the build.
                            The value of the system property
                            "java.vendor.url.bug" will be <vendor-url-bug>.
  --vendor-version <vendor-version>
                            Override the vendor version string baked into the
                            build,if any. The value of the system property
                            "java.vendor.version" will be <vendor-version>.
  --vendor-vm-bug-url <vendor-vm-bug-url>
                            Override the vendor VM bug URL baked
                            into the build.  The URL displayed in VM error
                            logs will be <vendor-vm-bug-url>.
  --vm <client|server|minimal|all>
                            Select the HotSpot VM in the output image.
                            Default is all

For options requiring a <pattern-list>, the value will be a comma separated
list of elements each using one the following forms:
  <glob-pattern>
  glob:<glob-pattern>
  regex:<regex-pattern>
  @<filename> where filename is the name of a file containing patterns to be
              used, one pattern per line

Some of them like --strip-native-commands and --release-info are not documented and thus subject to change. Still, it would be nice to be able to use those options. Since they are subject to change, maybe this Maven plugin could get an option to add those options without explicit support in case the changes break the plugin.

<plugin>
    <artifactId>maven-jlink-plugin</artifactId>
    <version>3.2.0</version>
    <extensions>true</extensions>
    <configuration>
        <otherArgs>--strip-native-commands</otherArgs>
    </configuration>
</plugin>

On the other hand the -vm option is also an undocumented plugin which has been added explicitly to this Maven plugin in #539
So maybe we could add all undocumented plugins explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions