Search code examples
javamavenmaven-embedder

Maven Embedder: how to add command option


I'm using Maven Embedder followingly:

MavenCli cli = new MavenCli();
int result = cli.doMain(new String[] { "process-resources" }, "tmp/projectdir", System.out, System.err);

This works, and is equivalent to running command line command

mvn process-resources

in directory

tmp/projectdir

However, I need to specify an option to Maven, so that Maven Embedder performs the equivalent to command line command

mvn -Dstage=local process-resources

How can this be done?


Solution

  • -Dstage=local is a system variable that is set by just giving it as the argument parameter to doMain():

    MavenCli cli = new MavenCli();
    int result = cli.doMain(new String[] { "-Dstage=local", "process-resources" }, "tmp/projectdir", System.out, System.err);