"pom"和"pom"之间有什么区别?具有范围“导入"的类型依赖性是否没有“导入"? [英] What is the difference between "pom" type dependency with scope "import" and without "import"?

查看:121
本文介绍了"pom"和"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>
...

然后发生的是,在other-pom-artifact-iddependencyManagement部分中定义的所有依赖项都包含在POM的dependencyManagement部分中.然后,您可以在POM的dependency部分(及其所有子POM)中引用这些依赖项,而不必包括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的常规依赖项,则other-pom-artifact-iddependency部分中的所有dependencies都将包含在您的项目中-但是,在dependencyManagement中定义的依赖项完全不包含other-pom-artifact-id部分.

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网站上有一个很好的页面,它比我可以更好地解释这一点,

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"之间有什么区别?具有范围“导入"的类型依赖性是否没有“导入"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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