我正在将我的项目从 maven 2 (2.2.1) 迁移到 maven 3 (3.1.0),并且我在 jar 版本方面遇到了一些问题。当我试图追查问题时,我遇到了一些来自依赖插件的不一致结果,这让我感到困惑。
当我在maven 3中尝试以下命令时:
mvn dependency:tree -Dincludes=commons-codec
结果是:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxx ---
[INFO] com.xxx.yyy:zzz:war:2.6-SNAPSHOT
[INFO] \- net.sourceforge.jwebunit:jwebunit-htmlunit-plugin:jar:2.2:test
[INFO] \- net.sourceforge.htmlunit:htmlunit:jar:2.5:test
[INFO] \- commons-codec:commons-codec:jar:1.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
所以结果表明将使用commons-codec-1.3.jar 。(maven 3 在打包时确实包含 commons-codec-1.3.jar)。
但是,如果我将选项 (-Dverbose) 添加到命令
mvn dependency:tree -Dincludes=commons-codec -Dverbose
结果将是
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxx ---
[INFO] com.xxx.yyy:zzz:war:2.6-SNAPSHOT
[INFO] +- net.sourceforge.jwebunit:jwebunit-htmlunit-plugin:jar:2.2:test
[INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.5:test
[INFO] | +- commons-httpclient:commons-httpclient:jar:3.1:test
[INFO] | | \- (commons-codec:commons-codec:jar:1.2:test - omitted for conflict with 1.3)
[INFO] | \- (commons-codec:commons-codec:jar:1.3:compile - scope updated from test; omitted for duplicate)
[INFO] \- xxx.yyy.zzz.core:www-core:jar:2.6-SNAPSHOT:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.2.2:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] \- xxx.yyy.zzz.security:datasecurity:jar:2.0:compile
[INFO] \- (commons-codec:commons-codec:jar:1.3:compile - omitted for conflict with 1.6)
[INFO] ------------------------------------------------------------------------
第二个结果表明版本1.2和1.3会因为冲突而被省略,maven 会使用1.6。显然情况并非如此,因为maven 3在 war 文件中打包了commons-codec-1.3.jar。
为什么 maven 3 中的插件在两种情况下建议了不同的依赖项(它不应该因为 -Dverbose 应该只显示省略了哪些依赖项以及为什么)?这是一个错误还是我错过了什么?
值得注意的是,maven 2会使用commons-codec-1.6.jar 打包。
邮编:
- 自 Maven 依赖插件的 2.5 版以来,dependency:tree 适用于 Maven 3 - Maven3 - 如何找到依赖解析?( mvn depedency:tree 不适用于 mvn3 )
- verbose:是否在序列化的依赖树中包含省略的节点。- http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html