我想通过阅读pom.xml文件而不连接到远程存储库,以编程方式打印maven依赖关系树(包括传递依赖关系在内的所有依赖关系)。
b4lqfgs41#
不太可能,抱歉。另外,您是否查看了此处的答案和评论?How can you display the Maven dependency tree for the plugins in your project?
rt4zxlrg2#
我建议您看一下maven resolver项目,其中有一些示例代码,作为起点可能已经足够了:https://github.com/apache/maven-resolver/tree/master/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples
gzszwxb43#
您可以通过使用ProcessBuilder检索maven的dependency:tree命令的结果来实现这一点。
ProcessBuilder
dependency:tree
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public static void main(String[] args) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("cmd.exe", "/c", "mvn -f \"C:\\myprojectpath\"", "dependency:tree"); try { Process process = processBuilder.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } int exitCode = process.waitFor(); System.out.println("\nExited with error code : " + exitCode); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
了解更多here .
3条答案
按热度按时间b4lqfgs41#
不太可能,抱歉。另外,您是否查看了此处的答案和评论?How can you display the Maven dependency tree for the plugins in your project?
rt4zxlrg2#
我建议您看一下maven resolver项目,其中有一些示例代码,作为起点可能已经足够了:
https://github.com/apache/maven-resolver/tree/master/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples
gzszwxb43#
您可以通过使用
ProcessBuilder
检索maven的dependency:tree
命令的结果来实现这一点。了解更多here .