JavaPackager icon indicating copy to clipboard operation
JavaPackager copied to clipboard

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

Open streamingdv opened this issue 1 year ago • 8 comments

I'm submitting a…

  • [ ] bug report
  • [ ] feature request
  • [x] other

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:

  • JavaPackager version: 1.7.5
  • OS version: Windows 11
  • JDK version: openjdk 21.0.1 2023-10-17 LTS
  • Build tool:
    • [ ] Maven
    • [x] Gradle

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

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

streamingdv avatar Dec 06 '23 22:12 streamingdv

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

fvarrui avatar Dec 13 '23 11:12 fvarrui

@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.

streamingdv avatar Dec 13 '23 11:12 streamingdv

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

fvarrui avatar Dec 13 '23 12:12 fvarrui

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

Xiphoseer avatar Jan 24 '24 10:01 Xiphoseer

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.
…

trashgod avatar Feb 22 '24 19:02 trashgod

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 avatar Feb 25 '24 20:02 fvarrui

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 avatar Feb 25 '24 21:02 fvarrui

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

fvarrui avatar Apr 23 '24 10:04 fvarrui

v1.7.6 released to Maven Central

fvarrui avatar Jun 30 '24 12:06 fvarrui