Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically?

I'm trying to create an intelliJ plugin that needs to execute maven targets on the current project. All the talk in the intertubes recommends using the MavenEmbedder. Good luck with that. The 2.0.4 version isn't well supported and there are no references for how to use it.

I gave it a whirl and ran into a wall where the embedder had not been initialized with all the fields it needs. Reflective private member injection? Awesome! Why would anyone need an obvious way to initialize an object?

It seems a few people are using a 2.1 version with some success. I have been unable to find that in a jar or even sources.

I went and checked out the 3.0 version of the embedder project: http://maven.apache.org/ref/3.0-beta-3/maven-embedder/ It does away with the MavenEmbedder object all together and seems to only support access through the main or doMain methods on MavenCli. Has anyone used these methods and can give some advice?

Yeah, the's not much in the way of documentation of MavenCli. The API is significatly simpler but i'd still like some examples. Here's one that works...

MavenCli cli = new MavenCli();
int result = cli.doMain(new String[]{"compile"},
        "/home/aioffe/workspace/MiscMaven",
        System.out, System.out);
System.out.println("result: " + result);

It takes a dir and runs the 'compile' phase...

How to Integrate Maven into Your Own Java Tool – Sourcetrail , Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically? Ask Question Good luck with that. The 2.0.4  The following are top voted examples for showing how to use org.apache.maven.cli.MavenCli.These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.

Working maven configuration for maven 3.1.1

Dependencies
<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-embedder</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.aether</groupId>
        <artifactId>aether-connector-wagon</artifactId>
        <version>0.9.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-http-lightweight</artifactId>
        <version>2.5</version>
    </dependency>
</dependencies>
Code
MavenCli cli = new MavenCli();

cli.doMain(new String[]{"clean", "compile"}, "project_dir", System.out, System.out);

Wagon - Dev - running maven programmatically, the , I think we can all agree on one thing: Managing dependencies by Opposed to that, using a dependency manager like Apache Maven If you like to give it a try, you'll find more example code here. import org.apache.maven.cli. void executeMavenInstall() { MavenCli maven = new MavenCli(); maven. 15 Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically? Nov 17 '10 13 How do you use a type outside of its own namespace in clojure?

The dependency matrix information for provided scopes and dynamically acquired components can be a bit confusing. It was for me, since it appeared to me that I got all the required items by direct or transitive dependency, but then remote resolution didn't work.

I wanted to jump to Maven 3.3.3 (latest as of 2015-05-25). I got it working without the sisu errors that presented when I tried to optimistically update to current versions of things specified here (and elsewhere). This is a project with a tag that worked with the example specified as of today using JDK8.

https://github.com/mykelalvis/test-maven-embedder/tree/20150525-working

Relevant deps (SLF4J is just so I can see the logs)

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-embedder</artifactId>
        <version>3.3.3</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.aether</groupId>
        <artifactId>aether-connector-basic</artifactId>
        <version>1.0.2.v20150114</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.aether</groupId>
        <artifactId>aether-transport-wagon</artifactId>
        <version>1.0.2.v20150114</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-http</artifactId>
        <version>2.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-provider-api</artifactId>
        <version>2.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-http-lightweight</artifactId>
        <version>2.9</version>
    </dependency>   

Running this is:

rm -r ~/.m2/repository/org/apache/maven/plugins/maven-clean-plugin/
mvn exec:java

Probably should have made it a unit test of some sort.

If someone has a superior solution for embedded Maven 3.3.3 (i.e. came up with a smaller or more range-oriented set of required dependencies), please post them.

Re: Invoking a plugin programmatically using maven 3 and scala, I have a very simple project that starts maven programmatically, as follows: import​ http://stackoverflow.com/questions/4206679/can-anyone-give-a-good-​example-of-using-org-apache-maven-cli-mavencli-programatt/  5 Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically? May 25 '15 3 What's the purpose of the Maven 3 ciManagement configuration?

to build on the comment from @StevePerkins, and using maven version 3.1.0,

I had to exclude the transitive dependency from aether-connector-wagon to wagon-provider-api to get it working.

pom.xml:

(...)
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-embedder</artifactId>
    <version>3.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.aether</groupId>
    <artifactId>aether-connector-wagon</artifactId>
    <version>0.9.0.M2</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-provider-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.maven.wagon</groupId>
    <artifactId>wagon-http</artifactId>
    <version>2.5</version>
    <scope>test</scope>
</dependency>
(...)

and here is a java example:

(...)
MavenCli cli = new MavenCli();

ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
ByteArrayOutputStream baosErr = new ByteArrayOutputStream();

PrintStream out = new PrintStream(baosOut, true);
PrintStream err = new PrintStream(baosErr, true);

cli.doMain( new String[] { "clean" }, new File("."), out, err );

String stdout = baosOut.toString("UTF-8");
String stderr = baosErr.toString("UTF-8");
(...)

full example here

Frequently Asked Technical Questions, When the DefaultMavenPluginManager is loaded, it's loaded as part of >> an org.​apache.maven:maven-core specific classloader. One of the  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

There is a dependency matrix for each version of maven-embedder, e.g. for 3.2.5: http://maven.apache.org/ref/3.2.5/maven-embedder/dependencies.html

Based on that I had to use org.apache.maven:maven-embedder:jar:3.2.5, org.apache.maven:maven-aether-provider:jar:3.2.5, and org.apache.maven.wagon:wagon-provider-api:jar:2.8.

It also fixes dependency on very old Guava library, since this version uses 18.0.

Selenium issue: UnreachableBrowserException for driver.get , How do I set up Maven so it will compile with a target and source JVM of my choice? Is it possible to This is as easy as adding the following property to your POM (or one of its parent POMs): See https://maven.apache.org/plugins Note that you must give the plugin prefix as the argument to plugin, not it's artifact ID. [​top]  running maven programmatically, the DefaultRemoteRepositoryManager.connectorFactories is empty. I have a very simple project that starts maven programmatically, as follows: import

TimMoore/mojo-executor: The Mojo Executor provides a , Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically?. I'm trying to create an intelliJ plugin that needs to execute maven  How to Integrate Maven into Your Own Java Tool If you like to give it a try, you’ll find more example code If you can’t find it programmatically or don

(MVN) Maven Options Cheat Sheet, Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically? I'm trying to create an intelliJ plugin that needs to execute maven  I am developing pde plugin where user projects are maven nature projects. My plugin requires m2e to handle project configuration from user perspective.

It's a simple library that does its job, and a lot of people are using it effectively in its I do want to make it clear, however, that I won't be personally working on any I hope the community of Mojo Executor users will help answer questions and groupId("org.apache.maven.plugins"), artifactId("maven-dependency-plugin"),  As you can see, we're using the same local repository location (since the site-generation artifacts will most likely be common to most sites), the same invoker instance (it's configured, we may as well reuse it), and the same set of goals per build.

Comments
  • If anyone else comes across this, you need to add three dependencies in order for Maven to fetch dependencies that aren't already in your local workstation's repo. "org.apache.maven:maven-embedder:3.0.5", "org.sonatype.aether:aether-connector-wagon:1.13.1", and "org.apache.maven.wagon:wagon-http:2.4" (exact versions may vary with future Maven releases). It drove me crazy figuring that out... and the embedded Maven documentation is absolutely non-existent.
  • @StevePerkins Thanks so much for this comment.
  • Thanks soo much @StevePerkins! FYI and BTW, for maven 3.1 these versions worked for me : "org.apache.maven:maven-embedder:3.1.0", "org.eclipse.aether:aether-connector-wagon:0.9.0.M2", "org.apache.maven.wagon:wagon-http:2.5".
  • For me (maven 3.0.4) this is working: org.apache.maven:maven-embedder:3.0.4, org.apache.maven.wagon:wagon-http-lightweight:2.5 and org.sonatype.aether:aether-connector-wagon:1.13.1