diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 350fa61c5d..004cf4e005 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -23,6 +23,7 @@ import com.google.common.io.Files; import com.google.inject.AbstractModule; import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.UnrecognizedOptionException; import org.apache.maven.BuildAbort; @@ -463,7 +464,7 @@ void cli( CliRequest cliRequest ) } else { - cliRequest.commandLine = new MergedCommandLine( cliManager.parse( cliRequest.args ), mavenConfig ); + cliRequest.commandLine = cliMerge( cliManager.parse( cliRequest.args ), mavenConfig ); } } catch ( ParseException e ) @@ -486,6 +487,45 @@ void cli( CliRequest cliRequest ) } } + private CommandLine cliMerge( CommandLine mavenArgs, CommandLine mavenConfig ) + { + CommandLine.Builder commandLineBuilder = new CommandLine.Builder(); + + // the args are easy, cli first then config file + for ( String arg : mavenArgs.getArgs() ) + { + commandLineBuilder.addArg( arg ); + } + for ( String arg : mavenConfig.getArgs() ) + { + commandLineBuilder.addArg( arg ); + } + + // now add all options, except for -D with cli first then config file + List