gpt4 book ai didi

java - 以所需格式列出 Maven 项目的依赖项

转载 作者:行者123 更新时间:2023-12-02 06:27:23 26 4
gpt4 key购买 nike

我正在尝试使用以下命令在 Maven 中生成依赖关系树

$ mvn dependency:tree -DoutputType=dot

输出如下所示

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test ---
[INFO] digraph "com.a:test:jar:1.0" {
[INFO] "com.a:test:jar:1.0" -> "org.apache.httpcomponents:httpclient:jar:4.5.5:compile" ;
[INFO] "com.a:test:jar:1.0" -> "com.google.code.gson:gson:jar:2.8.2:compile" ;
[INFO] "com.a:test:jar:1.0" -> "info.picocli:picocli:jar:2.3.0:compile" ;
[INFO] "com.a:test:jar:1.0" -> "log4j:log4j:jar:1.2.17:compile" ;
[INFO] "com.a:test:jar:1.0" -> "org.xerial:sqlite-jdbc:jar:3.21.0:compile" ;
[INFO] "org.apache.httpcomponents:httpclient:jar:4.5.5:compile" -> "org.apache.httpcomponents:httpcore:jar:4.4.9:compile" ;
[INFO] "org.apache.httpcomponents:httpclient:jar:4.5.5:compile" -> "commons-logging:commons-logging:jar:1.2:compile" ;
[INFO] "org.apache.httpcomponents:httpclient:jar:4.5.5:compile" -> "commons-codec:commons-codec:jar:1.10:compile" ;
[INFO] }
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

它具有直接依赖和传递依赖,我所期望的只是直接依赖,可以利用 grep 或一些标志 -Dexcludes 帮助实现以下输出

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test ---
[INFO] digraph "com.a:test:jar:1.0" {
[INFO] "com.a:test:jar:1.0" -> "org.apache.httpcomponents:httpclient:jar:4.5.5:compile" ;
[INFO] "com.a:test:jar:1.0" -> "com.google.code.gson:gson:jar:2.8.2:compile" ;
[INFO] "com.a:test:jar:1.0" -> "info.picocli:picocli:jar:2.3.0:compile" ;
[INFO] "com.a:test:jar:1.0" -> "log4j:log4j:jar:1.2.17:compile" ;
[INFO] "com.a:test:jar:1.0" -> "org.xerial:sqlite-jdbc:jar:3.21.0:compile" ;
[INFO] }
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

我期待像节点生态系统中的 npm ls --depth=0 这样的东西,深度标志有助于获得直接依赖关系。

注意:我无法使用dependency:list,因为我需要上述结构。

最佳答案

maven-dependency-plugin:list 插件目标通过 excludeTransitive 提供了这样的功能。选项。但由于您正在寻找图形输出格式,因此您无法使用它。

该选项是以编程方式解析 maven-dependency-plugin:tree 输出的输出并删除传递依赖项,即不以模块 Artifact 名称开头的行。

像下面这样的基本内容就可以了:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:tree -DoutputType=dot -DoutputFile=out_temp & grep "com.a:test:jar:1.0" out_temp > out_final.gv & echo } >> out_final.gv & rm out_temp

关于java - 以所需格式列出 Maven 项目的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55776695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com