在循环中执行 MavenCli 时出错(maven-embedder)? [英] Error when execute MavenCli in the loop (maven-embedder)?

查看:67
本文介绍了在循环中执行 MavenCli 时出错(maven-embedder)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在循环中执行maven命令有什么问题?目标是更新包列表的 pom.xml 版本.第一次迭代,maven 正确执行(更新 pom.xml),但是之后的所有 item 都会出错.

What is the problem when I execute the maven command in the loop ? The goal is to update the version of pom.xml of the list of bundles. The first iteration, maven execute correctly (update pom.xml), but it makes error for all item after.

for (String bundlePath: bundlesToUpdate)
{
    MavenCli cli = new MavenCli();
String[] arguments = {
    "-Dtycho.mode=maven", 
        "org.eclipse.tycho:tycho-versions-plugin:set-version", 
    "-DgenerateBackupPoms=false", 
    "-DnewVersion=" + version};
    int result = cli.doMain(arguments, bundlePath, System.out, System.err);
}

同样的代码错误:

`MavenCli cli = new MavenCli();
for (String bundlePath: bundlesToUpdate) 
{
    String[] arguments = {
    "-Dtycho.mode=maven", 
    "org.eclipse.tycho:tycho-versions-plugin:set-version", 
    "-DgenerateBackupPoms=false", 
    "-DnewVersion=" + version};
int result = cli.doMain(arguments, bundlePath, System.out, System.err);
}`

第一次,没关系:

[main] INFO org.eclipse.tycho.versions.manipulation.PomManipulator -   pom.xml//project/version: 2.2.6-SNAPSHOT => 2.2.7-SNAPSHOT
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - ------------------------------------------------------------------------
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - Reactor Summary:
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - 
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - XXXX project   ....................... SUCCESS [  0.216 s]
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - com.sungard.valdi.bus.fixbroker.client.bnp ........ SKIPPED
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - XXX project Feature ...................... SKIPPED
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - ------------------------------------------------------------------------
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - BUILD SUCCESS

之后的错误是:

[main] ERROR org.apache.maven.cli.MavenCli - Error executing Maven.
[main] ERROR org.apache.maven.cli.MavenCli - java.util.NoSuchElementException
  role: org.apache.maven.eventspy.internal.EventSpyDispatcher
roleHint: 
[main] ERROR org.apache.maven.cli.MavenCli - Caused by: null
[main] ERROR org.apache.maven.cli.MavenCli - Error executing Maven.
[main] ERROR org.apache.maven.cli.MavenCli - java.util.NoSuchElementException
      role: org.apache.maven.eventspy.internal.EventSpyDispatcher
roleHint: 

推荐答案

我发现的解决方案是使用 Maven Invoker,它可以很好地实现相同的功能:

The solution I found is to use Maven Invoker and it works fine for the same functionality:

    public class MavenInvoker {

    public static void main(String[] args) throws IOException, NoHeadException, GitAPIException 
{
    MavenInvoker toto = new MavenInvoker();

    toto.updateVersionMavenInvoker("2.2.8-SNAPSHOT", "TECHNICAL\\WEB" );
}

private InvocationRequest request = new DefaultInvocationRequest();
private DefaultInvoker invoker = new DefaultInvoker();

public InvocationResult updateVersionMavenInvoker(String newVersion, String folderPath)
{
    InvocationResult result = null;
    request.setPomFile( new File(folderPath+"\\pom.xml" ) );

    String version =  "-DnewVersion="+newVersion;
    request.setGoals( Arrays.asList("-Dtycho.mode=maven", 
            "org.eclipse.tycho:tycho-versions-plugin:set-version", 
            "-DgenerateBackupPoms=false", 
            version) );
    try {
        result = invoker.execute( request );
    } catch (MavenInvocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

}

这篇关于在循环中执行 MavenCli 时出错(maven-embedder)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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