gpt4 book ai didi

maven - 为什么dependencyManagement中有spring-boot-dependencies?

转载 作者:行者123 更新时间:2023-12-02 01:07:19 25 4
gpt4 key购买 nike

Spring 文档 Using Spring Boot without the parent POM显示对 spring-boot-dependencies 的依赖被添加到 dependencyManagement 部分。这真的正确吗?

spring-boot-dependencies 为所有依赖项指定版本属性。但是,这些属性在使用 spring-boot-dependencies 的 POM 中不可用。推测这是因为 spring-boot-dependenciesdependencyManagement 中。

spring-boot-dependencies 只包含 dependencyManagementpluginManagement。因此,似乎可以将 spring-boot-dependencies 作为依赖项(而不是dependencyManagement)包含在内,而无需添加不必要的依赖项。

那么为什么要将 spring-boot-dependencies 包含为 dependencyManagement

最佳答案

So why is spring-boot-dependencies to be included as dependencyManagement?

假设您有一个名为 projectA 的项目,并且您将 spring-boot-dependencies 添加到 dependencyManagement 部分pom.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>

如果你仔细观察,你会发现 dependencies 部分下声明的所有 Spring Boot 依赖项都不需要指定 version。它从 dependencyManagement 部分中指定的 spring-boot-dependencies 版本派生出 version

依赖管理的优点

  • 它通过在一处指定 Spring Boot 版本来集中依赖信息。从一个版本升级到另一个版本时,它确实很有帮助。

  • Spring Boot 依赖项的后续声明只是提到了库名,没有任何版本。在多模块项目中特别有用

  • 避免项目中不同版本的spring boot库不匹配。

  • 没有冲突。

关于maven - 为什么dependencyManagement中有spring-boot-dependencies?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46984069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com