我想从插件中调用 Maven 目标,并且不愿意接受将进程分叉作为初始化的成本。有没有办法做到这一点?
问问题
636 次
2 回答
0
我怀疑这是一种受支持的方法,但它对我有用。
/**
* @parameter expression="${session}"
* @required
* @readonly
*/
private MavenSession session;
/**
* @component
* @readonly
*/
private Maven maven;
/**
* @parameter default-value="${project.remoteArtifactRepositories}"
* @readonly
**/
protected List<ArtifactRepository> remoteArtifactRepositories;
/**
* The project's remote repositories to use for the resolution of plugins
* and their dependencies.
*
* @parameter default-value="${project.pluginArtifactRepositories}"
* @readonly
*/
private List<ArtifactRepository> pluginArtifactRepositories;
/**
* @parameter default-value="${localRepository}"
* @readonly
* */
private ArtifactRepository localRepository;
...
List<String> goals = ...
File pomFile = ...
MavenExecutionRequest req = new DefaultMavenExecutionRequest();
req.setPom(pomFile);
req.setBaseDirectory(pomFile.getParentFile());
req.setGoals(goals);
req.setProxies(session.getSettings().getProxies());
req.setMirrors(session.getSettings().getMirrors());
req.setLocalRepository(localRepository);
req.setRemoteRepositories(remoteArtifactRepositories);
req.setPluginArtifactRepositories(pluginArtifactRepositories);
MavenExecutionResult result = session.execute(req);
要内省处理,您可以继承 AbstractExecutionListener 并使用 req.setExecutionListener() 来应用它。
于 2012-07-17T19:15:33.097 回答
0
于 2012-07-19T14:10:14.160 回答