ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2022-04-15 00:32:10  阅读:368  来源: 互联网

标签:INFO compile jar tree Maven dependency org


一、指令指导文档:

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)

标签:INFO,compile,jar,tree,Maven,dependency,org
来源: https://www.cnblogs.com/cavan2021/p/16070267.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有