Maven 指令 mvn:dependency:tree 查看依赖

2022/4/15 6:14:19

本文主要是介绍Maven 指令 mvn:dependency:tree 查看依赖,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、指令指导文档:

https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html

二、常用参数详解

  • includes
    类型:String
    描述:显示包含依赖的jar包。
    格式[groupId]:[artifactId]:[type]:[version],支持通配符*。例如,org.apache.*将匹配groupid 以org.apache.开头的所有内容;:::*-SNAPSHOT匹配所有jar。

  • excludes
    类型:String
    描述:显示不包含依赖的jar包。
    格式[groupId]:[artifactId]:[type]:[version],支持通配符*

  • appendOutput
    类型:boolean
    描述:是否将输出内容追加到文件或覆盖它。
    默认值false

  • outputEncoding
    类型:String
    描述:无
    默认值: ${project.reporting.outputEncoding}

  • outputFile
    类型:File
    描述:如果指定,此参数将将依赖关系树写入指定的路径,而不是写入控制台。

  • outputType
    类型:String
    描述:如果指定,此参数将使用指定格式写入依赖关系树。当前支持的格式有:(text默认)dotgraphmltgf。这些附加格式可以绘制到图像文件中。
    默认值text

  • verbose
    类型:boolean
    描述:查看冲突和重复的具体情况
    默认值false

三、一般常用的命令

  • 查看项目依赖:
    mvn dependency:analyze

  • 查看项目直接和传递依赖:
    mvn dependency:tree

  • 冲突和重复的具体情况,用verbose参数
    mvn dependency:tree -Dverbose

  • 查看依赖树中包含某个groupId和artifactId的依赖链(注意-Dincludes后面是等于号)
    mvn dependency:tree -Dincludes=com.alibaba:fastjson

  • 查看依赖树中包含某个artifactId的依赖链(artifactId前面加上冒号)
    mvn dependency:tree -Dincludes=:fastjson

  • 查看依赖树中包含某个groupId的依赖链(-Dincludes后面跟上groupId)
    mvn dependency:tree -Dincludes=com.alibaba

  • 查看maven构建时有效的pom:
    mvn help:effective-pom

  • 重定向至文本文件
    mvn dependency:tree -D outputFile=dependency_tree.txt
    mvn dependency:tree -D outputFile=dependency_tree.txt -D outputType=dot

  • 查看冲突和重复的具体情况,用verbose参数
    mvn dependency:tree -Dverbose

“+-”符号表示该包后面还有其它依赖包,“-”表示该包后面不再依赖其它jar包。每个层级结尾处用 - 标记

以下面springboot项目为例,运行上述命令显示的结果:

https://gitee.com/tiankong0310/springboot-weixin-alipay?_from=gitee_search

执行mvn dependency:tree后的依赖(仅展示部分):

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ springboot-weixin-alipay ---
[INFO] com.fengdu:springboot-weixin-alipay:war:0.0.1-SNAPSHOT
[INFO] +- com.github.pagehelper:pagehelper-spring-boot-starter:jar:1.2.5:compile
[INFO] |  +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:1.3.2:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.3.RELEASE:compile
[INFO] |  |  |  +- com.zaxxer:HikariCP:jar:2.7.9:compile
[INFO] |  |  |  \- org.springframework:spring-jdbc:jar:5.0.7.RELEASE:compile
[INFO] |  |  |     \- org.springframework:spring-tx:jar:5.0.7.RELEASE:compile
[INFO] |  |  +- org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:1.3.2:compile
[INFO] |  |  +- org.mybatis:mybatis:jar:3.4.6:compile
[INFO] |  |  \- org.mybatis:mybatis-spring:jar:1.3.2:compile
[INFO] |  +- com.github.pagehelper:pagehelper-spring-boot-autoconfigure:jar:1.2.5:compile
[INFO] |  \- com.github.pagehelper:pagehelper:jar:5.1.4:compile
[INFO] |     \- com.github.jsqlparser:jsqlparser:jar:1.0:compile
[INFO] +- com.alibaba:druid-spring-boot-starter:jar:1.1.9:compile
[INFO] |  +- com.alibaba:druid:jar:1.1.9:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.3.RELEASE:compile

执行mvn dependency:tree -Dincludes=com.alibaba:后的依赖树:

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ springboot-weixin-alipay ---
[INFO] com.fengdu:springboot-weixin-alipay:war:0.0.1-SNAPSHOT
[INFO] \- com.alibaba:druid-spring-boot-starter:jar:1.1.9:compile
[INFO]    \- com.alibaba:druid:jar:1.1.9:compile

执行mvn dependency:tree -Dverbose后的依赖树,可以看到依赖是否存在版本冲突。由于示例代码没有冲突,所以截取了其他项目扫描的结果:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ esshop ---
[INFO] esshop:esshop:war:0.0.1-SNAPSHOT
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- org.hibernate:hibernate:jar:3.2.2.ga:compile
[INFO] |  \- (commons-collections:commons-collections:jar:2.1.1:compile - omitted for conflict with 3.2.1)
[INFO] +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] |  \- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
[INFO] |     \- (commons-collections:commons-collections:jar:3.1:compile - omitted for conflict with 3.2.1)
[INFO] +- org.springframework.security:spring-security-core:jar:2.0.4:compile
[INFO] |  \- (commons-collections:commons-collections:jar:3.2:compile - omitted for conflict with 3.2.1)
[INFO] +- org.apache.velocity:velocity:jar:1.5:compile
[INFO] |  \- (commons-collections:commons-collections:jar:3.1:compile - omitted for conflict with 3.2.1)
[INFO] \- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO]    \- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for duplicate)


这篇关于Maven 指令 mvn:dependency:tree 查看依赖的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程