某些情况下,需要通过Java
代码来调用maven
命令,可以依据以下的方式来做到
maven
依赖
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.0.1</version>
</dependency>
public class Main {
public static void main(String[] args) {
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File("/var/pom.xml"));
request.setGoals(Collections.singletonList("dependency:tree"));
Invoker invoker = new DefaultInvoker();
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
}
}
使用Java
代码解析maven pom.xml
,可参考文章https://blog.csdn.net/sweatOtt/article/details/85294408
使用Java
代码解析mvn dependency tree
结果,可参考 https://blog.csdn.net/sweatOtt/article/details/85295130