Is it possible to programmatically call a maven build?

Viewed 396

I have a project that is calling a maven plugin (open-api-generator) to make a build based on an api specification. I don't want to share the project but I'd like to create a jar that somewhat simulate a "mvn compile" using an internal maven pom.xml.

Is this possible?

2 Answers

Code :

MavenCli obj = new MavenCli();
obj.doMain(new String[]{"compile"}, "project_dir", System.out, System.out);
P

Add :

  1. maven-embedder
  2. aether-connector-wagon and
  3. wagon-http-lightweight

dependencies in your pom.xml.

Programatically it is possible to call the Shell command. For example with:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", "mvn compile /foo/bar");
Related