Skip to content

mvnup should not inherit MAVEN_ARGS environment variable #12464

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions