问题描述
从 Maven 2.0.9 开始有可能包含
Starting from Maven 2.0.9 there is possibility to include
<type>pom</type>
<scope>import</scope>
在 部分.
据我所知,它将被包含在这个 pom 中的依赖项替换",就好像它们最初在这里定义一样.
As I understand it, it will be "replaced" with dependencies included in this pom as if they were originally defined here.
上面的解决方案与没有 import
作用域的这个 pom 的简单依赖之间有什么区别(我看到后者被称为依赖分组")?唯一的区别是这种分组"依赖在解析依赖优先级时具有较低的优先级吗?
What is the difference between solution above and simple dependency to this pom without import
scope (I saw the latter being called "dependencies grouping")? Is the only difference that such "grouped" dependencies have lower priority while resolving dependencies precedence?
推荐答案
您只能导入托管依赖项.这意味着您只能导入其他 POM 到项目 POM 的 dependencyManagement
部分.即
You can only import managed dependencies. This means you can only import other POMs into the dependencyManagement
section of your project's POM. i.e.
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>other.pom.group.id</groupId>
<artifactId>other-pom-artifact-id</artifactId>
<version>SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
...
然后发生的是,在 other-pom-artifact-id
的 dependencyManagement
部分中定义的所有依赖项都包含在您的 POM 的 dependencyManagement中代码>部分.然后,您可以在 POM(及其所有子 POM)的
dependency
部分中引用这些依赖项,而无需包含 version
等.
What then happens is that all the dependencies defined in the dependencyManagement
section of the other-pom-artifact-id
are included in your POM's dependencyManagement
section. You can then reference these dependencies in the dependency
section of your POM (and all of its child POMs) without having to include a version
etc.
然而,如果在你的 POM 中你只是定义一个对 other-pom-artifact-id
的正常依赖,那么来自 dependency
部分的所有 dependencies
other-pom-artifact-id
的一部分被传递地包含在您的项目中 - 但是在 other-pom-artifact-id 的
根本不包括在内.dependencyManagement
部分中定义的依赖项
However if in your POM you simply define a normal dependency to other-pom-artifact-id
then all dependencies
from the dependency
section of the other-pom-artifact-id
are included transitively in your project - however the dependencies defined in the dependencyManagement
section of the other-pom-artifact-id
are not included at all.
所以基本上这两种不同的机制用于导入/包含两种不同类型的依赖项(托管依赖项和普通依赖项).
So basically the two different mechanisms are used for importing/including the two different types of dependencies (managed dependencies and normal dependencies).
maven 网站上有一个很好的页面,可以比我更好地解释这一点,Maven 中的依赖管理,它还包含关于导入依赖项.
There is a good page on the maven website, which can explain this far better than I can, Dependency Management in Maven and it also contains specific information on importing dependencies.
这篇关于"pom" 和有什么不一样?具有范围“导入"的类型依赖项没有“进口"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!