我想在插件中调用Maven的目标,并且不愿意接受将进程作为初始化的成本。有没有办法做到这一点?
答案 0 :(得分: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()来应用它。
答案 1 :(得分:0)