我有一个多模块Maven项目(https://github.com/veniltonjr/msplearning)
我需要的一个模块我需要以编程方式从Maven构建"clean install " 命令,但是当我调用这些目标的执行时,会发生以下错误:
java.lang.IllegalStateException: 未指定Maven应用程序目录,系统属性中未提供$ {maven.home}.请至少详细说明.
在Maven Invoker文档中说M2_HOME环境变量必须存在.
已经在我的SO中设置了这个变量.这不足以使该方法invoke有效吗?按照我运行相关方法的代码片段:
Invoker invoker = new DefaultInvoker();
invoker.setLocalRepositoryDirectory(new File("C:\\git\\msplearning"));
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(Arrays.asList("clean", "install"));
InvocationResult result = invoker.execute(request); // Exception occours here...
已经,谢谢!
编辑(解决方案)
我必须设置POM并设置Maven Home,在我的例子中是在M3_HOME环境变量中:
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File("C:\\git\\msplearning\\pom.xml"));
request.setGoals(Collections.singletonList("verify"));
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(System.getenv("M3_HOME")));
InvocationResult result = invoker.execute(request);
谢谢@RobertScholte和@khmarbaise!
| 归档时间: | 
 | 
| 查看次数: | 4640 次 | 
| 最近记录: |