What is the difference between quot;pomquot; type dependency with scope quot;importquot; and without quot;importquot;?(“pom和“pom有什么区别?范围为“import的类型依赖项;并且没有“进口?)
问题描述
从 Maven 2.0.9 开始有可能包含
Starting from Maven 2.0.9 there is possibility to include
<type>pom</type>
<scope>import</scope>
在 <dependencyManagement> 部分.
据我了解,它将被此 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"和“pom"有什么区别?范围为“import"的类型依赖项;并且没有“进口"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“pom"和“pom"有什么区别?范围为“import"的类型依赖项;并且没有“进口"?
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
