依赖性管理中的依赖性与Maven版本插件中的依赖性 [英] Dependencies in Dependency Management vs Dependencies in Maven versions plugin

查看:521
本文介绍了依赖性管理中的依赖性与Maven版本插件中的依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Maven versions:display-dependency-updates检查依赖项更新时,会得到两部分结果.

When I use Maven versions:display-dependency-updates to check dependencies updates, I get two sections of result.

第一:

依赖关系管理"中的以下依赖项较新 版本:

The following dependencies in Dependency Management have newer versions:

第二名:

依赖关系"中的以下依赖关系具有较新的版本:

The following dependencies in Dependencies have newer versions:

这两者有什么区别?

推荐答案

依赖性 POM的部分"定义了项目所依赖的工件(jar,zip等).即编译,运行等所需的工件.

The Dependency section of the POM defines the artifacts (jars, zip etc) upon which your project depends. i.e. the artifacts that it requires to compile, run etc.

POM的依赖管理部分用于管理依赖信息.

The Dependency Management section of the POM is used to manage dependency information.

因此,例如,在以下pom中,使用version=4.11scope = test在POM的dependencyManagement部分中完全定义了JUnit依赖关系.

So for example, in the following pom the JUnit dependency is defined completely in the dependencyManagement section of the POM with version=4.11 and scope = test.

dependency部分中,您只需要使用groupIdartifactId定义JUnit依赖关系,maven就会自动从dependencyManagement部分中选择版本和范围.

In the dependency section you simply need to define the JUnit dependency using the groupId and artifactId and maven automatically picks up the version and scope from the dependencyManagement section.

<?xml version="1.0" encoding="utf-8"?>
<project>

    ...
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
     <dependencyManagement>

     <dependencies>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
     <dependencies>
</project>

通常,您将在父POM中定义dependencyManagement部分,在其中定义所有依赖项的版本和范围.然后,在子模块中,您只需使用groupIdartifactId定义依赖项.这样一来,您就可以集中管理版本,这意味着您只需要在一个地方进行更新即可.

Usually you would define the dependencyManagement section in a parent POM, where you define the version and scope for all dependencies. Then in the child module's you simply need to define the dependencies using the groupId and artifactId. This allows you to centrally manage versions and means you only have to update them in one place.

所有这些在maven文档中都有更好的解释: https://maven.apache.org/guides/introduction/introduction -to-dependency-mechanism.html

All of this is far better explained in the maven documentation: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

版本Maven插件只是列出了在每个部分中找到的版本,因为在dependencies部分中可以覆盖在dependencyManagement部分中定义的version.

The Versions Maven Plugin is simply listing the versions found in each of these sections, as it is possible in the dependencies section to override the version that was defined in the dependencyManagement section.

这篇关于依赖性管理中的依赖性与Maven版本插件中的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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