范围与“导入”之间有什么区别?和“pom”类型依赖? [英] What is the difference between scope "import" and "pom" type dependency?

查看:148
本文介绍了范围与“导入”之间有什么区别?和“pom”类型依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从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>
...

然后发生的是<$ c中定义的所有依赖项$ c> dependencyManagement other-pom-artifact-id 部分包含在POM的 dependencyManagement 部分。然后,您可以在POM(及其所有子POM)的依赖部分中引用这些依赖项,而无需包含版本等。

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 然后所有依赖来自 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”类型依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆