谁能举一个以编程方式使用 org.apache.maven.cli.MavenCli 的好例子? [英] Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically?

查看:29
本文介绍了谁能举一个以编程方式使用 org.apache.maven.cli.MavenCli 的好例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个需要在当前项目上执行 maven 目标的 intelliJ 插件.intertubes 中的所有讨论都建议使用 MavenEmbedder.祝你好运.2.0.4 版本没有得到很好的支持,也没有关于如何使用它的参考.

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?

似乎有一些人在使用 2.1 版本并取得了一些成功.我一直无法在罐子甚至来源中找到它.

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.

我去查看了 embedder 项目的 3.0 版本:http://maven.apache.org/ref/3.0-beta-3/maven-embedder/ 它完全取消了 MavenEmbedder 对象,似乎只支持通过 MavenCli 上的 main 或 doMain 方法进行访问.有没有人用过这些方法,可以给点建议吗?

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?

推荐答案

是的,MavenCli 的文档并不多.API明显更简单,但我仍然想要一些例子.这是一个有效的...

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...

这篇关于谁能举一个以编程方式使用 org.apache.maven.cli.MavenCli 的好例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆