fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 134 forks source link

jlink deprecation warning for --compress '2' parameter on JDK21 #383

Closed streamingdv closed 5 months ago

streamingdv commented 11 months ago

I'm submitting a…

Short description of the issue/suggestion:

Deprecation warning is printed by jlink when used on a computer with JDK 21 installed

Steps to reproduce the issue/enhancement:

Use javapackger on a machine where JAVA_HOME is set to JDK 21

What is the expected behavior?

Ideally no deprecation warnings

What is the current behavior?

jlink produces following warning:

The 2 argument for --compress is deprecated and may be removed in a future release

Please tell us about your environment:

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

https://nipafx.dev/road-to-21-upgrade/#tools

fvarrui commented 11 months ago

Hi @streamingdv! Thanks for letting me know! Should this argument be omitted when JDK>=21 or should it be replaced with another one?

streamingdv commented 11 months ago

@fvarrui according to the link I posted above following is mentioned

jlink's option --compress now accepts values zip0 to zip9 instead of the more abstract 0, 1, 2.

So I guess on java >= 21 switching to--compress zip2 should get rid of the warning and should provide the same functionality but I di not check if zip2 does really the same thing as the old 2 parameter.

fvarrui commented 11 months ago

Oh! Sorry, I didn't notice the link 😅

Xiphoseer commented 10 months ago

FYI: 0-9 in the context of ZIP is the zlib/deflate compression level (which is a choice between speed and size and has nothing to do with the previous 0/1/2), and based on https://github.com/openjdk/jdk/blob/6d2f6408e417b267be0345f63656f232cf247b6d/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java#L48 the equivalent to --compress=2 seems to be zip-6.

Edit: See also https://github.com/openjdk/jdk/blob/67f29b16ef963ff1710e306da811633aa4e182ac/src/jdk.jlink/share/classes/jdk/tools/jmod/resources/jmod.properties#L85-L87

trashgod commented 9 months ago

For reference, given jlink version 21.0.2,

$ jlink --help
…
    --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.
        Deprecated values to be removed in a future release:
        0:  No compression. Equivalent to zip-0.
        1:  Constant String Sharing
        2:  Equivalent to zip-6.
…
fvarrui commented 9 months ago

Ok, as zip-6 seems to be the default value for --compress, now JP just omit --compress param if Java >= 21:

            // generates customized jre using modules
            CommandUtils.execute(
                    jlink, 
                    "--module-path", modulesDir, 
                    additionalModulePathsToParams(additionalModulePaths),
                    "--add-modules", modules, 
                    "--output", destinationFolder, 
                    "--no-header-files", 
                    "--no-man-pages", 
                    "--strip-debug", 
                    (VersionUtils.getJavaMajorVersion() < 21 ? "--compress=2" : null)
                );
fvarrui commented 9 months ago

Fixed!!! JP snapshot version 1.7.6-20240225.211252-1 released to Maven Central. Please, test it and give some feedback, so we can release this fix in JP 1.7.6. Thanks!

fvarrui commented 7 months ago

I tested It with different JDK versions and it seems to be working fine

fvarrui commented 5 months ago

v1.7.6 released to Maven Central