Add JDK management capabilities to Maven Wrapper
Overview
This PR adds comprehensive JDK download and management features to the Maven Wrapper, allowing projects to specify and automatically download specific JDK versions.
Key Features
- đ Automatic JDK download and installation
- đĻ JDK version management via maven-wrapper.properties
- đ§ Toolchain JDK support for multi-JDK builds
- đ SHA-256 checksum verification for security
- đ Cross-platform support (Windows, macOS, Linux)
- âī¸ Environment variable configuration
- âŠī¸ Backward compatibility with existing configurations
Changes Made
Core Components
- New:
JdkDownloaderclass for JDK management - Enhanced:
WrapperConfigurationwith JDK-related properties - Updated:
WrapperExecutorto handle JDK installation - Extended:
Installerwith JDK download capabilities
Scripts & Tools
- Updated:
mvnw/mvnw.cmdscripts with JDK environment support - Enhanced:
WrapperMojoMaven plugin with JDK parameters
Testing
- Fixed: Test issues and maintained backward compatibility
- Verified: All 31 tests pass successfully
New Configuration Properties
The following properties can now be added to maven-wrapper.properties:
# JDK Management
jdkVersion=17
jdkDistributionUrl=https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.7_7.tar.gz
jdkSha256Sum=aee68e7a34c7c6239d65b3bfbf0ca8f0b5b5b6e8e8e8e8e8e8e8e8e8e8e8e8e8
# Toolchain JDK (optional)
toolchainJdkVersion=11
toolchainJdkDistributionUrl=https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.19%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.19_7.tar.gz
# Force re-download (optional)
alwaysDownloadJdk=false
Environment Variables
New environment variables for configuration:
MAVEN_WRAPPER_JDK_VERSIONMAVEN_WRAPPER_JDK_DOWNLOADMAVEN_WRAPPER_TOOLCHAIN_JDK
Usage Example
# Set JDK version via Maven plugin
mvn wrapper:wrapper -Djdk=17
# Or configure manually in maven-wrapper.properties
echo "jdkVersion=17" >> .mvn/wrapper/maven-wrapper.properties
echo "jdkDistributionUrl=https://..." >> .mvn/wrapper/maven-wrapper.properties
# Run with automatic JDK download
./mvnw clean compile
Testing
- â All existing tests continue to pass
- â New functionality tested
- â Cross-platform compatibility verified
- â Backward compatibility maintained
Build Status
Tests run: 31, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
Breaking Changes
None - This enhancement is fully backward compatible with existing Maven Wrapper configurations.
Related Issues
This addresses the need for automatic JDK management in Maven Wrapper projects, similar to what Gradle Wrapper provides.
cc: @apache/maven-committers
Pull Request opened by Augment Code with guidance from the PR author
Can we have an example of how to configure different JDKs by different vendors, eg Azul Zulu, IBM Semeru or Amazon Corretto?
To document: Which is the default if no URL was given? Can this change in the future? If so, who (in terms of which tech) decides on that (doc only)?
To test:
- [ ] What is the exception and behaviour when behind a firewall? I remember that mvnw left an empty jar file due to wget being the default and no error check (return code/http/timeout) was done.
What with only-script type? ... it is a default
I have two questions on that work:
- does it belong to maven wrapper - concretely if my project needs some binaries should we add the hability to download it too "genericly"?
- do we want something a bit more flexible like a strict url (i was thinking to reuse sdkman or zulu like yupiik env manager -> https://github.com/yupiik/tools-maven-plugin/tree/master/env-manager/src/main/java/io/yupiik/dev/provider)
It's only a POC, so your suggestions are very welcomed ! I'll enhance it based on your feedback. I wanted to gauge the interest first đ
@gnodet yep, 100% thinking out loud but I'm still not a big fan of wrapper and it is worse if it becomes an env manager (as soon as it manages the jdk it is then you'll also need to setup other stuff so it becomes an env manager). Wonder if it wouldn't be worth being its own project at the end, could even enable to manage multiple jdk cause maven supports it but not this PR (for test matrix run without complex CI setup or broken setup reincluding the compilation - just 100% surefire/failsafe executions). So probably worth either joining Yupiik effort or spawning a new project from my window since it will likely be way more than wrapper scope (it is where I am in terms of thoughts to be transparent).
What with
only-scripttype? ... it is a default
The current PR only supports the only-script mode. Anything else could require starting a JVM and kinda defeats the purpose of the new feature...
I just found out https://github.com/foojayio/discoapi/tree/main which may be closer to what we want that reusing seaman. @rmannibucau wdyt ?
Yeah discospi was built for such things
Is it possible to extract the URL to a constant so it's only defined in one place?