Visitar URL original
[Backport maven-4.0.x] Fix #2520: default maven.mainClass in Java instead of classworlds config by gnodet · Pull Request #12889 · apache/maven · GitHub
Skip to content

[Backport maven-4.0.x] Fix #2520: default maven.mainClass in Java instead of classworlds config - #12889

Merged
gnodet merged 1 commit into
maven-4.0.xfrom
backport/12875-to-4.0.x
Aug 28, 2026
Merged

gnodet merged 1 commit into
maven-4.0.xfrom
backport/12875-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport of #12875 to maven-4.0.x.

Fixes Maven Wrapper and IDE compatibility broken with Maven 4.0.0-beta-5+ because maven.mainClass is not set when launching through external tools.

Changes:

  • m2.conf: Hardcode main is org.apache.maven.cling.MavenCling from plexus.core — no variable resolution needed
  • MavenCling.java: Check maven.mainClass system property and delegate to the specified class via reflection when set
  • New MavenClingTest.java with delegation tests

Cherry-picked cleanly from a8be2cb.

…fig (#12875)

Move the main class defaulting from classworlds property resolution to
Java code. MavenCling is now hardcoded as the entry point in m2.conf
and delegates to the class specified by -Dmaven.mainClass via
reflection when set. This fixes the Maven Wrapper and IDE integration
by removing the dependency on classworlds resolving ${maven.mainClass}.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0 milestone Aug 28, 2026
@gnodet gnodet added bug Something isn't working backport labels Aug 28, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clean cherry-pick of already-approved #12875 to maven-4.0.x. The diff is byte-for-byte identical to the original, all delegation targets (MavenEncCling, MavenShellCling, MavenUpCling) exist on 4.0.x with the correct public static int main(String[], ClassWorld) signatures, and CI is fully green across all platforms and JDK versions.

The reflection-based delegation in delegateMain is correct: it uses the context class loader (appropriate for classworlds), properly unwraps InvocationTargetException, and re-throws IOException/RuntimeException/Error without wrapping.

✅ LGTM — two minor style observations (not blocking):

  1. MavenCling.java lines 79-87: instanceof checks use old-style casts rather than pattern matching (if (cause instanceof IOException ioe)) which is used elsewhere in the codebase. Same observation from the original PR review.
  2. MavenClingTest.java line 107: assertEquals(true, DelegateTarget.invoked) could be assertTrue(DelegateTarget.invoked).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@gnodet gnodet modified the milestones: 4.0.0, 4.0.0-rc-7 Aug 28, 2026
@gnodet
gnodet merged commit 46b5e37 into maven-4.0.x Aug 28, 2026
24 checks passed
@gnodet
gnodet deleted the backport/12875-to-4.0.x branch August 28, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant