传递依赖如何为二级依赖工作
How transitive dependency work for second level dependency
我有以下依赖关系树。
[INFO] +- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] | +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] | +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.6:compile
当我在 pom 文件中添加依赖项 "commons-lang" 作为顶级依赖项时,它会自动删除 common-lang 的传递依赖项,即使没有将其从 pom 文件中排除。
[INFO] +- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] | +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] | +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | | +- javax.inject:javax.inject:jar:1:compile
当我们从 jasperreports 中排除它时,它应该排除 common-lang。
当在您的项目中声明依赖项时,pom maven 将使用该声明而不是传递依赖项。
maven 依赖关系树中不显示省略的依赖关系,我刚刚了解到,自 maven-dependency-plugin 3.0 版以来,不再支持详细选项 - 这将显示省略的依赖关系。
当我尝试在 maven 命令行(对于 "mvn dependency:tree -Dverbose=true")提供 -Dverbose 选项时,我看到了这个:
Verbose not supported since maven-dependency-plugin 3.0
在
中查看对答案的评论
Dependency Mediation 是您所说的规则。这是maven管理传递依赖的规则之一。
它会根据它在 pom 中最接近的定义将 commons-lang 放入依赖树中。
您可以在此处阅读所有规则:
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
所以引用他们:
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM.
并且 commons-lang 的依赖从未被移除,它在传递树中的位置已经改变。现在已经变成一级依赖了。
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] \- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | +- javax.inject:javax.inject:jar:1:compile
[INFO] | +- stax:stax:jar:1.2.0:compile
[INFO] | | \- stax:stax-api:jar:1.0.1:compile
[INFO] | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile
我有以下依赖关系树。
[INFO] +- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] | +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] | +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.6:compile
当我在 pom 文件中添加依赖项 "commons-lang" 作为顶级依赖项时,它会自动删除 common-lang 的传递依赖项,即使没有将其从 pom 文件中排除。
[INFO] +- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] | +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] | +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | | +- javax.inject:javax.inject:jar:1:compile
当我们从 jasperreports 中排除它时,它应该排除 common-lang。
当在您的项目中声明依赖项时,pom maven 将使用该声明而不是传递依赖项。
maven 依赖关系树中不显示省略的依赖关系,我刚刚了解到,自 maven-dependency-plugin 3.0 版以来,不再支持详细选项 - 这将显示省略的依赖关系。
当我尝试在 maven 命令行(对于 "mvn dependency:tree -Dverbose=true")提供 -Dverbose 选项时,我看到了这个:
Verbose not supported since maven-dependency-plugin 3.0
在
Dependency Mediation 是您所说的规则。这是maven管理传递依赖的规则之一。
它会根据它在 pom 中最接近的定义将 commons-lang 放入依赖树中。
您可以在此处阅读所有规则:
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
所以引用他们:
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM.
并且 commons-lang 的依赖从未被移除,它在传递树中的位置已经改变。现在已经变成一级依赖了。
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] \- net.sf.jasperreports:jasperreports:jar:6.5.1:compile
[INFO] +- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:compile
[INFO] +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] | +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] | +- javax.inject:javax.inject:jar:1:compile
[INFO] | +- stax:stax:jar:1.2.0:compile
[INFO] | | \- stax:stax-api:jar:1.0.1:compile
[INFO] | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile