“pom"和“pom"有什么区别?范围为“import"的类型依赖项;并且没有“进口"?

What is the difference between quot;pomquot; type dependency with scope quot;importquot; and without quot;importquot;?(“pom和“pom有什么区别?范围为“import的类型依赖项;并且没有“进口?)
本文介绍了“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-iddependencyManagement 部分中定义的所有依赖项都包含在您的 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 部分中的所有 dependenciesother-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"的类型依赖项;并且没有“进口"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)