gnodet opened a new pull request, #12875:
URL: https://github.com/apache/maven/pull/12875
## Summary
Fixes #2520 — Maven Wrapper (and IDEs like IntelliJ) broken with Maven
4.0.0-beta-5+ because `maven.mainClass` is not set when launching through
external tools.
**Root cause:** `m2.conf` used `main is ${maven.mainClass}` which required
classworlds property resolution. When external tools bypassed the `mvn`
scripts, `-Dmaven.mainClass` was never set, causing `ConfigurationException: No
such property: maven.mainClass`. The previous fix (PR #10998, rc-5) added `set
maven.mainClass default` in `m2.conf`, but this kept the defaulting in
classworlds config rather than Java — as noted by @gnodet in the [issue
discussion](https://github.com/apache/maven/issues/2520#issuecomment-2406145979).
**Fix:** Move the main class defaulting from classworlds property resolution
to Java code:
- **`m2.conf`**: Hardcode `main is org.apache.maven.cling.MavenCling from
plexus.core` — no variable resolution needed, no possibility of classworlds
`ConfigurationException`
- **`MavenCling.java`**: Check `maven.mainClass` system property in the
ClassWorld Launcher entry point and delegate to the specified class via
reflection when set (e.g., `MavenEncCling`, `MavenShellCling`, `MavenUpCling`)
This makes `MavenCling` the Java-level default entry point that all external
tools can rely on without any special configuration.
## Behavior
| Scenario | Before | After |
|----------|--------|-------|
| `mvn` script (normal) | `-Dmaven.mainClass=MavenCling` → classworlds
resolves | `-Dmaven.mainClass=MavenCling` → classworlds calls `MavenCling` → no
dispatch |
| `mvn --enc` | `-Dmaven.mainClass=MavenEncCling` → classworlds resolves |
`-Dmaven.mainClass=MavenEncCling` → `MavenCling` delegates to `MavenEncCling` |
| Maven Wrapper (no `-Dmaven.mainClass`) | `m2.conf` default resolves |
classworlds calls `MavenCling` directly — no resolution needed |
| IDE (no `-Dmaven.mainClass`) | `m2.conf` default resolves | classworlds
calls `MavenCling` directly — no resolution needed |
## Test plan
- [x] New `MavenClingTest` with 3 tests: delegation to valid class, unknown
class error, missing method error
- [x] All new tests pass
- [x] `mvn verify -pl impl/maven-cli -DskipTests` — build + format checks
pass
- [x] Pre-existing test failures are unrelated (MimirInfuser version
mismatch)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]