Skip to content

mvnup should not inherit MAVEN_ARGS environment variable #12464

Closed

Description

@gnodet

The mvnup shell script delegates to mvn --up "$@", and the mvn launcher unconditionally prepends $MAVEN_ARGS to the command line (line 299 in bin/mvn):

eval exec "$cmd" '$MAVEN_ARGS' '"$@"'

When MAVEN_ARGS contains build-specific flags (e.g. -ntp, -T4, -U), these are passed to MavenUpCling which does not recognize them.

The current workaround in PR #12454 is a retry loop in CommonsCliUpgradeOptions.CLIManager.parse() that catches UnrecognizedOptionException and strips unknown options one by one — this is fragile and hides real argument errors from the user.

Proposed fix

In the mvn shell script (bin/mvn and bin/mvn.cmd), skip $MAVEN_ARGS when the main class is not the default MavenCling. The handle_args function already detects --up/--enc/--shell to set MAVEN_MAIN_CLASS; use that to gate MAVEN_ARGS inclusion:

# Only pass MAVEN_ARGS for the default Maven build command
if [ "$MAVEN_MAIN_CLASS" = "org.apache.maven.cling.MavenCling" ]; then
  eval exec "$cmd" '$MAVEN_ARGS' '"$@"'
else
  eval exec "$cmd" '"$@"'
fi

Same change needed in bin/mvn.cmd.

Once fixed, the retry loop in CommonsCliUpgradeOptions can be removed — replaced with a simple super.parse(args) that fails fast on truly unrecognized options.

Activity

  1. cstamas commented on Jul 10, 2026

    @cstamas
    Member

    IMHO, ideally no other command than mvn should behave as documented. Currently, all commands pretty much do the same, even if it makes no sense for them.

  2. added 2 commits that reference this issue on Jul 10, 2026
  3. added 3 commits that reference this issue on Jul 11, 2026
    b384725
    5c1357e
    60d8f32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions