I'm using Maven in the context of another build-tool (leiningen for Clojure, but this should not matter), and I would like to know how I would call a plugin like dependency:build-classpath programmatically (i.e. via the Maven-API, not via the mvn
-command).
Use the Maven Invoker API. Its quick and easy.
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "/path/to/pom.xml" ) );
request.setGoals( Collections.singletonList( "install" ) );
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File("/usr"));
try
{
invoker.execute( request );
}
catch (MavenInvocationException e)
{
e.printStackTrace();
}
pom.xml:
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.1.1</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With