【问题标题】:Display omitted versions in maven dependency:tree?在 Maven 依赖项中显示省略的版本:树?
【发布时间】:2016-06-05 23:07:43
【问题描述】:

在 Eclipse 中,当我转到 Maven Dependency Hierarchy 页面时,我得到的输出说明了哪些冲突导致版本被忽略:

但是,如果我使用dependency:tree,那将被省略,我只会看到实际使用的 evrsions:

|  +- commons-httpclient:commons-httpclient:jar:3.1:compile
|  +- commons-codec:commons-codec:jar:1.4:compile
|  +- commons-io:commons-io:jar:2.4:compile
|  +- commons-net:commons-net:jar:3.1:compile
|  +- javax.servlet:servlet-api:jar:2.5:compile

以及后来实际引用的版本...

+- commons-collections:commons-collections:jar:3.1:compile

有什么办法可以让dependency:tree输出因冲突而省略的版本?

谢谢!

【问题讨论】:

    标签: java eclipse maven pom.xml maven-dependency-plugin


    【解决方案1】:

    是的,您可以通过将verbose 属性设置为true 来获得省略的工件:

    是否在序列化的依赖树中包含省略的节点。

    此属性默认为false。在命令行上,您将拥有

    mvn dependency:tree -Dverbose=true
    

    【讨论】:

    • 这仅在依赖插件版本 3.0 之前有效。对于 3.1,您必须使用选项 -X。但是您仍然看不到省略的依赖项。那我需要做什么?
    • 我发现的唯一选择是使用旧版本的依赖插件:mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true。不过有一个警告:Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution。总比没有好。
    • 对我来说,-Dverbose 确实适用于 Maven 3.6。但它不能与-DoutputType=dot 一起使用
    【解决方案2】:

    根据this-Dverbose=true 参数在插件 3.0 及更高版本中被忽略。您需要使用旧版本;上面的链接建议以下内容(对我有用):

    mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true
    

    【讨论】:

      【解决方案3】:

      我建议使用depgraph-maven-plugin

      • 要查看所有依赖项,请将showDuplicates 设置为true
        • 这将包括 dependency:tree 使用 verbose 选项显示的依赖项
      • 要查看冲突,请将 showConflicts 设置为 true
      • 具有各种过滤器来包含/排除项目
      • 可以导出为各种格式,包括可以用GraphViz渲染的点文件

      示例配置:

      <plugin>
          <groupId>com.github.ferstl</groupId>
          <artifactId>depgraph-maven-plugin</artifactId>
          <version>3.3.0</version>
          <configuration>
              <showDuplicates>true</showDuplicates>
              <showConflicts>true</showConflicts>
              <includes>
                  <!-- groupId:artifactId:type:classifier -->
                  <include>com.mycompany*:*</include>
              </includes>
          </configuration>
      </plugin>
      

      然后在你的项目中运行mvn depgraph:graph,在target/dependency-graph.dot中找到一个新文件。

      请注意,您可以包含范围为provided 的插件,这样它就不会包含在任何构建工件中。

      【讨论】:

      • 一点补充:如果你想快速分析你的模块依赖(不添加插件到你的项目),只需在你的模块文件夹中运行mvn com.github.ferstl:depgraph-maven-plugin:3.3.0:graph -DrepeatTransitiveDependenciesInTextGraph -DshowVersions -DgraphFormat=text -DshowGroupIds -DshowConflicts -DshowDuplicates
      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 2015-10-17
      • 1970-01-01
      • 2014-05-23
      • 2012-02-14
      • 1970-01-01
      • 2015-04-03
      相关资源
      最近更新 更多