Unable to run maven tasks through MavenCli (maven-embedder)

送分小仙女□ 提交于 2019-12-05 08:03:13
Tunaki

Since Maven 3.3.1, there is a new system property called maven.multiModuleProjectDirectory. It is set by default to the root of the project (project base directory) by the mvn (or mvn.bat) script (so that is why you never experienced such an error before).

Therefore, when running Maven through maven-embedder, you also need to set this system property (see source code where the check is made). It needs to be set to the project root.

To set this system property, you can adjust your call to doMain and add

"-Dmaven.multiModuleProjectDirectory=" + projectRoot

to the given arguments. An example would be

int result = cli.doMain(new String[] { "-Dmaven.multiModuleProjectDirectory=" + projectRoot, "install" }, "/path/to/project", System.out, System.err);

Alternatively, you can call:

System.setProperty("maven.multiModuleProjectDirectory", projectRoot);

before invoking MavenCli.doMain method, where projectRoot points to root of the project you are building.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!