JavaPackager
JavaPackager copied to clipboard
jlink deprecation warning for --compress '2' parameter on JDK21
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
Hi @streamingdv! Thanks for letting me know! Should this argument be omitted when JDK>=21 or should it be replaced with another one?
@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.
Oh! Sorry, I didn't notice the link 😅
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
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.
…
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)
);
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!
I tested It with different JDK versions and it seems to be working fine
v1.7.6 released to Maven Central