rwf*_*fbc 5 dependencies dependency-management maven spring-boot
Spring 文档在没有父 POM 的情况下使用 Spring Boot显示对的依赖项spring-boot-dependencies已添加到该dependencyManagement部分。这真的正确吗?
spring-boot-dependencies 指定所有依赖项的版本属性。但是,这些属性在使用 的 POM 中不可用spring-boot-dependencies。据推测,这是因为spring-boot-dependencies位于dependencyManagement.
spring-boot-dependency 仅包含dependencyManagement和pluginManagement。因此,似乎可以将spring-boot-dependencies其作为依赖项(而不是 dependencyManagement)包含在内,而无需添加不必要的依赖项。
那么为什么要spring-boot-dependencies被列为dependencyManagement?
那么为什么 spring-boot-dependencies 被包含为 dependencyManagement 呢?
假设您有一个名为 的项目projectA,并将其添加spring-boot-dependencies到.dependencyManagementpom.xml
<project>
<groupId>com.iovation.service</groupId>
<artifactId>projectA</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>1.5.8.RELEASE</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Spring Boot Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
</project>
Run Code Online (Sandbox Code Playgroud)
如果您仔细观察,您会发现该部分下声明的所有 Spring Boot 依赖项dependencies都不需要指定version. 它源自本节中指定的version版本。spring-boot-dependenciesdependencyManagement
它通过在一处指定 Spring Boot 版本来集中依赖信息。在从一个版本升级到另一版本的过程中,它确实很有帮助。
Spring Boot 依赖项的后续声明仅提及库名称,没有任何版本。在多模块项目中特别有用
避免了项目中不同版本的spring boot库的不匹配。
没有冲突。
| 归档时间: |
|
| 查看次数: |
13469 次 |
| 最近记录: |