Skip to content

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Jul 16, 2025

🚀 JDK Management for Maven Wrapper

This PR adds comprehensive JDK management capabilities to Maven Wrapper using the Foojay Disco API, enabling automatic JDK download and installation for the only-script distribution type.

✨ Key Features

🎯 Automatic JDK Management

  • Automatic JDK download and installation for only-script distribution
  • 34+ JDK distributions supported via Foojay Disco API
  • Version resolution: Major versions (e.g., 17) resolve to latest patch versions
  • Multi-platform support: Linux, macOS, Windows with architecture detection
  • Toolchain integration: Automatic toolchains.xml generation for multi-JDK builds
  • Dynamic LTS detection: Uses Disco API to identify LTS versions (no hardcoded heuristics)
  • Bypass option: MVNW_SKIP_JDK environment variable to use system JDK

🔧 Configuration Options

# Basic JDK configuration
jdkVersion=17
jdkDistribution=temurin

# Toolchain JDK for multi-version builds
toolchainJdkVersion=11
toolchainJdkDistribution=corretto

# Update policies
jdkUpdatePolicy=daily  # never, daily, weekly, monthly, always, interval:X

# Direct URLs (optional)
jdkDistributionUrl=https://example.com/jdk.tar.gz
jdkSha256Sum=abc123...

🆔 Environment Variables

# Skip JDK management and use system JDK
export MVNW_SKIP_JDK=true

# Enable verbose output
export MVNW_VERBOSE=true

# Configure JDK settings
export MAVEN_WRAPPER_JDK_VERSION=17
export MAVEN_WRAPPER_JDK_DISTRIBUTION=temurin

📦 Supported Distributions

Popular Distributions:

  • temurin - Eclipse Adoptium (default)
  • corretto - Amazon Corretto
  • zulu - Azul Zulu
  • liberica - BellSoft Liberica
  • oracle_open_jdk - Oracle OpenJDK
  • microsoft - Microsoft OpenJDK
  • semeru - IBM Semeru

Specialized Distributions:

  • graalvm_ce11, graalvm_ce17 - GraalVM Community Edition
  • sap_machine - SAP Machine
  • dragonwell - Alibaba Dragonwell
  • jetbrains - JetBrains Runtime
  • bisheng - Huawei BiSheng
  • kona - Tencent Kona
  • mandrel - Red Hat Mandrel

Complete list: Foojay Disco API

🛠️ Usage Examples

Maven Plugin

# Generate wrapper with JDK management
mvn wrapper:wrapper -Dtype=only-script -Djdk=17 -DjdkDistribution=temurin

# With toolchain support
mvn wrapper:wrapper -Dtype=only-script -Djdk=21 -DjdkDistribution=corretto -DtoolchainJdk=17 -DtoolchainJdkDistribution=temurin

Properties Configuration

# Production: Pin exact version
jdkVersion=17.0.14
jdkDistribution=temurin
jdkUpdatePolicy=never

# Development: Auto-update to latest patches
jdkVersion=17
jdkDistribution=temurin
jdkUpdatePolicy=daily

Bypassing JDK Management

# Use system JDK instead of wrapper-managed JDK
export MVNW_SKIP_JDK=true
./mvnw clean compile

# Windows
set MVNW_SKIP_JDK=true
mvnw.cmd clean compile

# Useful for CI matrix testing
MVNW_SKIP_JDK=true ./mvnw test

Multi-JDK Toolchain Setup

# Main JDK for build
jdkVersion=21
jdkDistribution=temurin

# Toolchain JDK for compilation
toolchainJdkVersion=17
toolchainJdkDistribution=corretto

🏗️ Implementation Details

Architecture

  • Shell-based implementation for only-script distribution type
  • No Java dependency for JDK installation (avoids chicken-and-egg problem)
  • Foojay Disco API integration for JDK resolution and download
  • Cross-platform support with native shell scripts (Unix) and PowerShell (Windows)
  • API URL constants for maintainability and easy version updates

Dynamic LTS Detection

  • Real-time LTS detection via Disco API /major_versions endpoint
  • Intelligent caching to avoid repeated API calls
  • Robust fallback to hardcoded LTS list if API unavailable
  • Accurate warnings showing current LTS versions (6, 7, 8, 11, 17, 21)
  • Future-proof - automatically includes new LTS versions when released

Distribution Validation

  • Comprehensive validation against known Disco API distributions
  • Helpful error messages showing all available distributions
  • Typo prevention with clear distribution suggestions

Bypass Mechanisms

  • MVNW_SKIP_JDK: Skip JDK management entirely, use system JDK
  • Direct URLs: Override version/distribution resolution with exact URLs
  • Environment variables: Configure JDK settings without modifying properties

Caching & Performance

  • Intelligent caching with configurable update policies
  • SHA-256 verification for security
  • Efficient downloads with resume support
  • Version resolution caching to minimize API calls

Security Features

  • HTTPS downloads by default
  • SHA-256 checksum verification for all downloads
  • Automatic checksum resolution from Disco API
  • Manual checksum override for direct URLs

🎯 Benefits

For Developers

  • Zero JDK setup - automatic download and installation
  • Consistent environments across team members
  • Easy distribution switching for testing
  • Toolchain support for multi-JDK projects
  • Accurate LTS guidance with real-time data
  • Flexible bypass options for special cases

For CI/CD

  • Reproducible builds with exact version pinning
  • No pre-installed JDK requirement in build environments
  • Flexible update policies for different environments
  • Multi-platform consistency
  • Matrix testing support with MVNW_SKIP_JDK

For Projects

  • Simplified onboarding - no JDK installation instructions needed
  • Version consistency across all environments
  • Easy JDK upgrades via configuration changes
  • Professional distribution support (34+ options)
  • Troubleshooting options with bypass mechanisms

🔄 Migration Path

Existing projects can easily adopt JDK management:

  1. Switch to only-script distribution type
  2. Add JDK configuration to maven-wrapper.properties
  3. Remove manual JDK setup from documentation
  4. Enjoy automatic JDK management
# Simple migration command
mvn wrapper:wrapper -Dtype=only-script -Djdk=17 -DjdkDistribution=temurin

🧪 Testing

  • Cross-platform testing (Linux, macOS, Windows)
  • Multiple JDK distributions verified
  • Version resolution tested (major → patch versions)
  • Toolchain integration validated
  • Error handling and validation tested
  • Caching and update policies verified
  • Dynamic LTS detection confirmed with API
  • MVNW_SKIP_JDK bypass functionality tested

📚 Documentation

Comprehensive documentation added:

  • JDK_MANAGEMENT.md - Complete feature guide
  • Configuration examples for all use cases
  • Environment variable documentation
  • Troubleshooting guide for common issues
  • Migration instructions for existing projects
  • MVNW_SKIP_JDK usage examples

🎉 Summary

This PR transforms Maven Wrapper into a complete JDK management solution that:

  • Eliminates JDK setup friction for developers
  • Ensures consistent environments across teams
  • Supports 34+ professional JDK distributions
  • Provides flexible configuration options for all use cases
  • Maintains security with checksum verification
  • Offers excellent performance with intelligent caching
  • Uses dynamic LTS detection with real-time API data
  • Requires zero maintenance for future JDK versions
  • Includes bypass mechanisms for special cases and troubleshooting

The implementation is production-ready, well-tested, and thoroughly documented, making it easy for projects to adopt automatic JDK management while maintaining flexibility for edge cases.

@mosabua
Copy link
Member

mosabua commented Jul 16, 2025

Whoa .. thats amazing!

@gnodet gnodet force-pushed the origin-feature-jdk-enhancement branch 2 times, most recently from bbe1815 to 0160a9c Compare July 16, 2025 20:43
@norrisjeremy
Copy link

Is my understanding correct that the mvnw script now downloads and installs a JDK distrubution instead of using the system JDK?

@gnodet
Copy link
Contributor Author

gnodet commented Jul 17, 2025

Is my understanding correct that the mvnw script now downloads and installs a JDK distrubution instead of using the system JDK?

That's not completely exact. The JDK download is an opt-in if you add the required properties. The default behaviour is unchanged. There's also a MVNW_SKIP_JDK env var to skip using the JDK indicated by those properties (can be useful when running in a JDK matrix in a CI job).

@gnodet gnodet force-pushed the origin-feature-jdk-enhancement branch 3 times, most recently from 0160a9c to 4aaf12a Compare July 17, 2025 07:58
@norrisjeremy
Copy link

Is my understanding correct that the mvnw script now downloads and installs a JDK distrubution instead of using the system JDK?

That's not completely exact. The JDK download is an opt-in if you add the required properties. The default behaviour is unchanged. There's also a MVNW_SKIP_JDK env var to skip using the JDK indicated by those properties (can be useful when running in a JDK matrix in a CI job).

Ok, thanks! I was concerned that the default behavior was changing and users would have to explicitly opt-out to prevent it.

@gnodet gnodet force-pushed the origin-feature-jdk-enhancement branch 2 times, most recently from 47fe90a to a4c27d7 Compare July 22, 2025 06:02
@gnodet
Copy link
Contributor Author

gnodet commented Jul 22, 2025

Currently broken by foojayio/discoapi#124

@gnodet gnodet force-pushed the origin-feature-jdk-enhancement branch 3 times, most recently from 6b3dd03 to 53aaaa0 Compare July 23, 2025 17:16
@norrisjeremy
Copy link

To confirm my understanding: if we add the new JDK properties into .mvn/wrapper/maven-wrapper.properties, but then set the MVNW_SKIP_JDK=true env variable, mvnw will use the system JDK as always and not attempt to download a JDK?

@gnodet
Copy link
Contributor Author

gnodet commented Jul 23, 2025

To confirm my understanding: if we add the new JDK properties into .mvn/wrapper/maven-wrapper.properties, but then set the MVNW_SKIP_JDK=true env variable, mvnw will use the system JDK as always and not attempt to download a JDK?

Correct

@norrisjeremy
Copy link

To confirm my understanding: if we add the new JDK properties into .mvn/wrapper/maven-wrapper.properties, but then set the MVNW_SKIP_JDK=true env variable, mvnw will use the system JDK as always and not attempt to download a JDK?

Correct

Perfect, thanks! This sounds like a great feature which we can use with our dev team to allow easy bootstrapping of the preferred JDK distribution on their workstations, whilst continuing to have our Github Actions CI pipelines use the system provided JDK.

boolean warningShown = false;

// Check for non-LTS versions
if (isNonLtsVersion(version)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you also want this for Maven 3? Otherwise maybe use multiline string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You log a lot of single line strings to generate something that looks like a multiline string? Since java 13 (?) Java supports texts blocks like. As we set Java 17 for Maven 4, maybe we can make use of this here if the change is only aiming at Maven 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. So this is currently not focused on Maven 4. Also, using multiline strings changes the output, as only the first line will be prepended with [WARN] afaik, so it kinda messes the output which is not correctly aligned anymore.


## Distribution Type Support

**Important**: JDK management is **only available for the `only-script` distribution type**. This design choice avoids the chicken-and-egg problem where Java is needed to download Java.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to line 20, where for the first time it is mentioned that only-script is the only supported way

```properties
# JDK Management
jdkVersion=17 # Resolves to latest 17.x (e.g., 17.0.14)
jdkDistribution=temurin # Disco API distribution name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disco API was never mentioned before, not suddenly pops up in a comment. Should be mentioned before so people can look up whats available


## Supported JDK Distributions

The Maven Wrapper supports 34+ JDK distributions through the Foojay Disco API using native distribution names:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the number and only mentioned Disco API. Also add link to there

@gzm55
Copy link
Contributor

gzm55 commented Jul 24, 2025

Exciting feature!

@gnodet
is it possible to support the .java-version file for defining the default JDK version of a project? It is normally generated by jenv to lock a project local JDK.

@gzm55
Copy link
Contributor

gzm55 commented Jul 24, 2025

# Useful for CI matrix testing
MVNW_SKIP_JDK=true ./mvnw test

@gnodet how about to support selecting dynamicly JDK version via an environment, then the mvnw can pin almost the jdk matrix by project.

@gnodet
Copy link
Contributor Author

gnodet commented Jul 24, 2025

# Useful for CI matrix testing
MVNW_SKIP_JDK=true ./mvnw test

@gnodet how about to support selecting dynamicly JDK version via an environment, then the mvnw can pin almost the jdk matrix by project.

I've added env vars to override the JDK properties.

@gzm55
Copy link
Contributor

gzm55 commented Jul 24, 2025

# Useful for CI matrix testing
MVNW_SKIP_JDK=true ./mvnw test

@gnodet how about to support selecting dynamicly JDK version via an environment, then the mvnw can pin almost the jdk matrix by project.

I've added env vars to override the JDK properties.

should we make all the env vars all has the same prefix MVNW_

@carlspring
Copy link

I'm not on the committers list, but this looks like fantastic new feature! :)

@gnodet
Copy link
Contributor Author

gnodet commented Jul 24, 2025

# Useful for CI matrix testing
MVNW_SKIP_JDK=true ./mvnw test

@gnodet how about to support selecting dynamicly JDK version via an environment, then the mvnw can pin almost the jdk matrix by project.

I've added env vars to override the JDK properties.

should we make all the env vars all has the same prefix MVNW_

They do AFAIK, did I miss something ?

@jimisola
Copy link
Contributor

jimisola commented Jul 25, 2025

  • Have you considered security concerns with the distribution url? A person might check the source code, the POM etc for security stuff but fail to understand the implication of a distibution url that leads to a malicious JDK? I reckon if you use jdkDistribution then it uses the Foojay Disco API which seems to be some sort of assurance of the integrity of that JDK.

Isn't the fact that you can pin the SHA-256 hash via the jdkSha256Sum property cover the security perspectives?

No. That only verifies that the file specified in the properties file is the file that you actually downloaded.
It does not provide any "security guarantees" of that JDK.

E.g.

# Direct URLs (optional)
jdkDistributionUrl=https://hackers.com/jdk_that_has_malicous_code.tar.gz
jdkSha256Sum=<a valid sha256 sum for that tarball>.

This can of course be said for regular dependencies as well. The difference here is that users are used to dependencies they're not used to a random JDK being pulled in without their knowledge.

And there tends to be infrastructure (at least from an Enterprise perspective) to scan dependencies for CVEs etc which jdkDistributionUrl would completely circumvent.

Just to be clear, I'm not against the jdkDistributionUrl - it might be useful. But, when it is used the user should be made aware (read: warned about security risks) and then actively have to approve it (which can be explicitly pre-approved using a command line option or similar).

@norrisjeremy
Copy link

No. That only verifies that the file specified in the properties file is the file that you actually downloaded. It does not provide any "security guarantees" of that JDK.

E.g.

# Direct URLs (optional)
jdkDistributionUrl=https://hackers.com/jdk_that_has_malicous_code.tar.gz
jdkSha256Sum=<a valid sha256 sum for that tarball>.

This can of course be said for regular dependencies as well. The difference here is that users are used to dependencies they're not used to a random JDK being pulled in without their knowledge.

And there tends to be infrastructure (at least from an Enterprise perspective) to scan dependencies for CVEs etc which jdkDistributionUrl would completely circumvent.

I sort of surprised that an enterprise that is that particular about security would use maven-wrapper in the first place, but to each their own. 🤷‍♂️

@gnodet
Copy link
Contributor Author

gnodet commented Jul 25, 2025

Great feature! From a user perspective (especially if I wear the Enterprise and not the Open Source Developer one) I have few things:

  • Do you plan to release this feature a new major version of Maven Wrapper? I consider this a major change (although not necessarily breaking) since the default behaviour changes and the user has to opt-out using MVNW_SKIP_JDK. That is, a simple update of Maven Wrapper should need cause me to suddently have a bunch of JDK installed without my knowledge (especially, since we use SDKMan already).

Not really because the default behaviour DOES NOT change. You have to first opt-in and specify the JDK version. Once you have opted-in, you can then opt-out with MVNW_SKIP_JDK.

  • Is there a way that this could be integrated with SDKMan for users that want that?

Not sure. That was really my first attempt. Unfortunately, sdkman does not keep track of old releases, which is a problem from a reproducibility pov.

  • Have you considered security concerns with the distribution url? A person might check the source code, the POM etc for security stuff but fail to understand the implication of a distibution url that leads to a malicious JDK? I reckon if you use jdkDistribution then it uses the Foojay Disco API which seems to be some sort of assurance of the integrity of that JDK.

I agree with Jeremy here. A simple to secure things is to use an exact url + sha256.

If you want to keep some versatility, another way would be to be able to provide an alternative REST endpoint that could be implemented within an entreprise. At runtime, only https://api.foojay.io/disco/v3.0/packages is actually used. So an env var could specify a REST endpoint different than the default https://api.foojay.io/disco/v3.0.

@jimisola
Copy link
Contributor

I sort of surprised that an enterprise that is that particular about security would use maven-wrapper in the first place, but to each their own. 🤷‍♂️

It's not a matter of Enterprise or not. When I develop on my spare time I don't necessarily want to have a bunch of JDKs downloaded to my computer without my knowledge.

@jimisola
Copy link
Contributor

  • Do you plan to release this feature a new major version of Maven Wrapper? I consider this a major change (although not necessarily breaking) since the default behaviour changes and the user has to opt-out using MVNW_SKIP_JDK. That is, a simple update of Maven Wrapper should need cause me to suddently have a bunch of JDK installed without my knowledge (especially, since we use SDKMan already).

Not really because the default behaviour DOES NOT change. You have to first opt-in and specify the JDK version. Once you have opted-in, you can then opt-out with MVNW_SKIP_JDK.

Maybe I'm missing something here. Who is that has to opt-in?

If I download an open source project that uses Maven Wrapper and then run it with mvnw do I have to opt-in for the download of a JDK (jdkDistribution/jdkDistributionUrl) to be enabled?

  • Is there a way that this could be integrated with SDKMan for users that want that?

Not sure. That was really my first attempt. Unfortunately, sdkman does not keep track of old releases, which is a problem from a reproducibility pov.

Agreed. Yes, it is.

  • Have you considered security concerns with the distribution url? A person might check the source code, the POM etc for security stuff but fail to understand the implication of a distibution url that leads to a malicious JDK? I reckon if you use jdkDistribution then it uses the Foojay Disco API which seems to be some sort of assurance of the integrity of that JDK.

I agree with Jeremy here. A simple to secure things is to use an exact url + sha256.

See my use-case above. I don't see how an exact url and an sha256 in an open source project's maven-wrapper.properties helps.

If you want to keep some versatility, another way would be to be able to provide an alternative REST endpoint that could be implemented within an entreprise. At runtime, only https://api.foojay.io/disco/v3.0/packages is actually used. So an env var could specify a REST endpoint different than the default https://api.foojay.io/disco/v3.0.

Yes, I saw that that was added. But, I don't think that it's relevant to the security use-case I wrote above - unless I miss understood something.

@jimisola
Copy link
Contributor

@gnodet After giving this some more though, the feature is great but I'm actually leaning towards that this feature is in the wrong place.

The Maven Wrapper project is just that "it wraps Maven" (and the name implies just that) - not JDKs.
What this PR is doing is wrapping the JDK.

I don't think it obvious from a user perspective that a Maven Wrapper also wraps the JDK (and it never will be with that name) and I'm not sure that the two should be mixed. It's convenient but is it the right place?

Perhaps, there needs to be a JDK Wrapper?
I get a sense of "virtual environments" with Maven Wrapper and JDK Wrapper. Perhaps, the two should be merged into something new that is not Maven Wrapper?

@norrisjeremy
Copy link

norrisjeremy commented Jul 25, 2025

If I download an open source project that uses Maven Wrapper and then run it with mvnw do I have to opt-in for the download of a JDK (jdkDistribution/jdkDistributionUrl) to be enabled?

You could just use your own Maven installation instead of using the projects embedded mvnw script and not have to worry about any of this.
It's not as if the only way to run Maven is via the wrapper...

@jimisola
Copy link
Contributor

If I download an open source project that uses Maven Wrapper and then run it with mvnw do I have to opt-in for the download of a JDK (jdkDistribution/jdkDistributionUrl) to be enabled?

You could just use your own Maven installation instead of using the projects embedded mvnw script and not have to worry about any of this. It's not as if the only way to run Maven is via the wrapper...

Yes, I can, but you are missing the point completely.

Maven Wrapper was created so that I would have to think of what Maven version to use with the project.
Simply use mvnw and you're set.

Your "suggestion"/"workaround" is because the original functionality of Maven Wrapper is "broken".

@norrisjeremy
Copy link

I agree with Jeremy here. A simple to secure things is to use an exact url + sha256.

I do wonder: how would the checksum pining work for multi-arch / multi-OS?
Is it possible to specify multiple checksums so that a user could specify checksums for differing build environments (i.e. Windows x64, macOS arm64, Linux x64, etc.)?

@gnodet
Copy link
Contributor Author

gnodet commented Jul 25, 2025

I sort of surprised that an enterprise that is that particular about security would use maven-wrapper in the first place, but to each their own. 🤷‍♂️

It's not a matter of Enterprise or not. When I develop on my spare time I don't necessarily want to have a bunch of JDKs downloaded to my computer without my knowledge.

Then you can easily opt-out by default by adding export MVNW_SKIP_JDK=true in your shell config.

@gnodet
Copy link
Contributor Author

gnodet commented Jul 25, 2025

I agree with Jeremy here. A simple to secure things is to use an exact url + sha256.

I do wonder: how would the checksum pining work for multi-arch / multi-OS? Is it possible to specify multiple checksums so that a user could specify checksums for differing build environments (i.e. Windows x64, macOS arm64, Linux x64, etc.)?

Oops, I had not thought about that... that clearly looks broken ;-)

@jimisola
Copy link
Contributor

It's not a matter of Enterprise or not. When I develop on my spare time I don't necessarily want to have a bunch of JDKs downloaded to my computer without my knowledge.

Then you can easily opt-out by default by adding export MVNW_SKIP_JDK=true in your shell config.

Yes, I know. I think it's here that we disagree. You are adding new functionality that fundamentally changes Maven Wrapper (wrapping Maven and adding Maven locally - not JDKs) but you want users to opt-out when they might even be aware of the new functionality.

I'm not convinced that default being opt-in is the right way to go.

@rmannibucau
Copy link

@gnodet @jimisola add another script (mvnb (maven builder or whatever name)) and be it?

@bmarwell
Copy link
Contributor

I would like to test it on AIX (bash and maybe the not so old ksh). The default ksh is buggy...

However, most AIX systems don't have a direct internet connection. Does anyone have access to such a system?

Copy link
Member

@olamy olamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaut opt out could be to not download jdk and ask for user approval.
But tbh I'm never using mvnw :)

@bmarwell
Copy link
Contributor

bmarwell commented Aug 5, 2025

At least for specific environments (eg CI) off by default? Corporate environments...

@jimisola
Copy link
Contributor

jimisola commented Aug 5, 2025

I posted a summary of my comments and concerns in the dev mailing list. Reposting here.

Feedback on JDK Auto-Download Feature

First of all, I think the JDK auto-download feature is a valuable enhancement, but I do have a few concerns I'd like to highlight:

🔧 Scope Creep & Naming

Maven Wrapper is intended to wrap Maven—not a JDK.

Adding JDK management expands its scope significantly.

It might be more appropriate as a standalone "JDK Wrapper" or part of a broader environment-management tool.

🧭 User Experience (UX)

Even though JDK configuration is technically opt-in, in practice, a user cloning a repository and running ./mvnw may unknowingly trigger a JDK download.

This behavior may surprise developers and potentially even break their environments.

Prompting or clearly notifying users before downloading could help.

While the feature is opt-in, this is a substantial behavioral and major change.

I recommend releasing it under a new major version to avoid surprises for users upgrading Maven Wrapper.

🔐 Security & License Transparency

Using jdkDistributionUrl with jdkSha256Sum confirms file integrity, but it doesn’t guarantee security or trustworthiness of the downloaded JDK.

A user could unknowingly fetch a malicious JDK.

Additionally, users might inadvertently download a JDK under a license incompatible with their project's license or internal policies—leading to unintentional licensing obligations.

@rmannibucau
Copy link

interesting it can be made to openjdk maybe and then maven could only use it if jdkw exists? can be better for the community as a whole

@Bukama
Copy link
Contributor

Bukama commented Aug 5, 2025

At least for specific environments (eg CI) off by default? Corporate environments...

yes. I'm on your side - not allowed and/or able to just download what I want.

@gnodet
Copy link
Contributor Author

gnodet commented Aug 5, 2025

At least for specific environments (eg CI) off by default? Corporate environments...

yes. I'm on your side - not allowed and/or able to just download what I want.

That would be opting-out based on an env var. That's already doable. Just add export MVNW_SKIP_JDK=true in your shell setup and you're done. Or don't use tool that automate your environment setup.
How do you control before hand which dependencies are downloaded when you run a maven build ? Maven does not know by default that you're in a corporate env and that you do not want to go to central by default. Same here... You need to either disable this feature, or make it point to a different endpoint where you can control the JDK being downloaded.

@Bukama
Copy link
Contributor

Bukama commented Aug 5, 2025

How do you control before hand which dependencies are downloaded when you run a maven build ?

At my security has an Nexus IQ Server with whitelist/blacklist activated.

@gnodet
Copy link
Contributor Author

gnodet commented Aug 5, 2025

How do you control before hand which dependencies are downloaded when you run a maven build ?

At my security has an Nexus IQ Server with whitelist/blacklist activated.

My point unless you have a DNS redirect on your computer, it means you have a proxy or a maven mirror defined to point to your Nexus instead of Maven Central. You'll have to do something similar for whitelisting/blacklisting JDK. Granted, there's currently no tool to do that, but Maven does not provide a repository manager, an external tool should be able to easily do that, it's just a few rest calls to handle.

@olamy
Copy link
Member

olamy commented Aug 5, 2025

TBH, this feature without auto download of the JDK is probably useless :).
People use mvnw rather than mvn on purpose and by choice.
If some systems doesn't like it just add the env var or simply use mvn

@bmarwell
Copy link
Contributor

bmarwell commented Aug 6, 2025

That would be opting-out based on an env var. That's already doable. Just add export MVNW_SKIP_JDK=true in your shell setup and you're done. Or don't use tool that automate your environment setup.

I was thinking of reading out the CI variable. It's often used like CI=true or even CI=jenkins.

For Maven wrapper itself, I have set the download URL to an internal repo in the maven-wrapper.properties. As the default repo is changeable via environment variable, running wrapper:wrapper is no problem.

It's a bit different for JDKs, because there's no standardized URL/GAV coordinates. But of course doable. But yes, I also keep JDKs in my internal Nexus, specifying a GAV and repo instead would be a nice alternative, but out of the scope of this PR. But we could check it's not impossible in the future.

Also, it might be a significant increase in data transfer for Foojay and hosters, which might or might not be a problem. Just thinking about "tragedy of the commons" from Brian Fox.

But don't get me wrong, I really love this PR. I think we should merge it.

if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
verbose "Found wget ... using wget"
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
if download_file_with_retry "$distributionUrl" "$TMP_DOWNLOAD_DIR/$distributionUrlName" 3 2; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s we have a detecting tools like wget, curl in download_file_with_retry we not need here check for the same


```bash
# Generate wrapper with JDK management support
mvn wrapper:wrapper -Dtype=only-script -Djdk=17 -DjdkDistribution=temurin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only-script is default

mvn wrapper:wrapper -Dtype=only-script -Djdk=17 -DjdkDistribution=temurin
```

The `only-script` distribution uses shell scripts (Unix) and PowerShell (Windows) to handle JDK download and installation directly, without requiring Java to be pre-installed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check in code that only-script type is used with jdk properties?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added in site menu somewhere

@slawekjaranowski
Copy link
Member

As we add a many code that will be not used is standard configuration I would like to split it to separate files and add only when is needed.

We can include code by . dot operator

Similar as we do with debug with option includeDebugScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.