Skip to content

Fix #12464: Skip MAVEN_ARGS for non-default main classes (--up, --enc, --shell)#12465

Open
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:fix-12464-mvnup-should-not-inherit-maven_args-en
Open

Fix #12464: Skip MAVEN_ARGS for non-default main classes (--up, --enc, --shell)#12465
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:fix-12464-mvnup-should-not-inherit-maven_args-en

Conversation

@gnodet

@gnodet gnodet commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • In bin/mvn, gate $MAVEN_ARGS inclusion on MAVEN_MAIN_CLASS equaling the default MavenCling. When --up, --enc, or --shell is used, the handle_args function sets MAVEN_MAIN_CLASS to a different class — skip MAVEN_ARGS in that case to avoid passing unrecognized build-specific flags (e.g. -ntp, -T4, -U) to sub-commands.
  • Apply the same fix in bin/mvn.cmd by clearing MAVEN_ARGS when the main class is not MavenCling (safe because the script runs inside @setlocal).
  • Debug logging (MAVEN_DEBUG_SCRIPT) is also updated to reflect the conditional behavior.

Closes #12464

Test plan

  • Module builds successfully (mvn verify -pl apache-maven)
  • Run MAVEN_ARGS="-ntp -T4" mvn --up check — should no longer fail with unrecognized option errors
  • Run MAVEN_ARGS="-ntp -T4" mvn clean install — should still pass MAVEN_ARGS as before
  • Run MAVEN_ARGS="-ntp" mvn --enc — should not fail on -ntp
  • Verify MAVEN_DEBUG_SCRIPT=1 mvn --up check does not print MAVEN_ARGS in debug output

🤖 Generated with Claude Code

… --enc, --shell)

When MAVEN_MAIN_CLASS is not the default MavenCling (i.e., when using
--up, --enc, or --shell), skip prepending $MAVEN_ARGS to the command
line. MAVEN_ARGS may contain build-specific flags like -ntp, -T4, -U
that are not recognized by MavenUpCling, MavenEncCling, or
MavenShellCling.

The handle_args function already sets MAVEN_MAIN_CLASS for these
sub-commands — use that to gate MAVEN_ARGS inclusion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet marked this pull request as ready for review July 10, 2026 17:46
@gnodet gnodet added this to the 4.0.0-rc-6 milestone Jul 10, 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.

Review — Skip MAVEN_ARGS for Non-Default Main Classes

Clean, well-scoped fix that gates $MAVEN_ARGS on the main class being the default MavenCling. Both Unix and Windows scripts are updated with platform-idiomatic approaches.

Analysis

  • Unix (bin/mvn): Conditional if/else around the eval exec — debug output is also correctly gated so it reflects what's actually executed.
  • Windows (bin/mvn.cmd): Clears MAVEN_ARGS before the exec line — scoped inside @setlocal/@endlocal so it doesn't leak to the caller.
  • Edge case: If a user intentionally puts args in MAVEN_ARGS for sub-tools, those will be silently dropped. This is correct — MAVEN_ARGS is documented as Maven-specific, and sub-tools have their own option sets.
  • Complements #12454: With the retry loop reverted, this shell-level gate is the clean solution — sub-tools will properly fail fast on truly unrecognized options.

No issues found. LGTM (own PR, can't APPROVE). ✅


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 added a commit to gnodet/maven that referenced this pull request Jul 10, 2026
New PR apache#12465 (skip MAVEN_ARGS for sub-tools). COMMENT, own PR.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

mvnup should not inherit MAVEN_ARGS environment variable

2 participants