The 依赖性 https://maven.apache.org/pom.html#DependenciesPOM 的部分定义了项目所依赖的工件(jar、zip 等)。即编译、运行等所需的工件。
The 依赖管理 https://maven.apache.org/pom.html#Dependency_ManagementPOM 的部分用于管理依赖关系信息。
例如,在下面的 pom 中,JUnit 依赖项完全定义在dependencyManagement
POM 的部分version=4.11
and scope = test
.
In the dependency
部分您只需要使用以下命令定义 JUnit 依赖项groupId
and artifactId
maven 会自动从以下位置获取版本和范围dependencyManagement
部分。
<?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>
通常你会定义dependencyManagement
父 POM 中的部分,您可以在其中定义所有依赖项的版本和范围。然后在子模块中,您只需使用以下命令定义依赖项groupId
and artifactId
。这使您可以集中管理版本,并且意味着您只需在一处更新它们。
所有这些在 Maven 文档中都有更好的解释:https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
The 版本 Maven 插件 http://www.mojohaus.org/versions-maven-plugin/只是列出了每个部分中找到的版本,因为它可以在dependencies
部分来覆盖version
中定义的dependencyManagement
部分。