范围“进口”之间的差异和“pom”类型依赖 [英] difference between scope "import" and "pom" type dependency

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

问题描述

从Maven 2.0.9开始,有可能包含

 < type> pom< / type> 
< scope> import< / scope> dependencyManagement 部分中的

据我所知,它将被替换为这个pom中包含的依赖项,就像它们原来在这里定义一样。



上面的解决方案与简单的依赖关系有什么区别pom没有导入范围(我看到后者被称为依赖关系分组)?唯一的区别是这样的分组依赖关系在解决依赖性前提下具有较低的优先级?

解决方案

您只能导入管理依赖关系。这意味着您只能将其他POM导入项目的POM的 dependencyManagement 部分。即

  ... 
< dependencyManagement>
<依赖关系>
<依赖关系>
< groupId> other.pom.group.id< / groupId>
< artifactId> other-pom-artifact-id< / artifactId>
< version> SNAPSHOT< / version>
< scope> import< / scope>
< type> pom< / type>
< / dependency>
< / dependencies>
< / dependencyManagement>
...

然后发生的是,所有在 dependencyManagement 部分的 other-pom-artifact-id 包含在您的POM的 dependencyManagement 部分。然后,您可以在POM(及其所有子POM)的依赖关系部分中引用这些依赖关系,而无需包含版本 etc。



但是,如果在您的POM中,您只需定义一个与 other-pom-artifact-id 然后从 other-pom-artifact-id的依赖关系部分中的所有依赖关系 在您的项目中被过渡性地包含在内,而 other-pom-artifact-id的 dependencyManagement 部分中定义的依赖项

因此,基本上两种不同的机制用于导入/包括两种不同类型的依赖关系(托管依赖和正常的依赖关系)。



在maven网站上有一个很好的页面,这可以解释这远远好于我可以, Maven中的依赖管理,它还包含有关导入依赖项


Starting from Maven 2.0.9 there is possibility to include

<type>pom</type>
<scope>import</scope>

in the dependencyManagement section. As I understand it will be "replaced" with dependencies included in this pom as if they were originally defined here.

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 precendence?

解决方案

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

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.

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

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天全站免登陆