Spring documentation Using Spring Boot without the parent POM显示对spring-boot-dependencies
的依赖项已添加到dependencyManagement
部分。这真的是正确的吗?
spring-boot-dependencies为所有依赖项指定版本属性。但是,这些属性在使用spring-boot-dependencies
的POM中不可用。想必,这是因为spring-boot-dependencies
在dependencyManagement
中。
spring-boot-dependencies仅包括dependencyManagement
和pluginManagement
。因此,在不添加不必要的依赖项的情况下,似乎可以包含spring-boot-dependencies
作为依赖项(而不是dependencyManagement)。
那么为什么要将spring-boot-dependencies
包含在dependencyManagement
中呢
发布于 2017-10-28 06:23:27
这绝对是正确的。请参阅Using Spring Boot without the parent POM!
发布于 2017-10-28 07:12:14
那么,为什么要将
-boot-dependencies包含在dependencyManagement中呢?
假设您有一个名为projectA
的项目,并将spring-boot-dependencies
添加到pom.xml
中的dependencyManagement
部分。
<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
。
依赖项管理的优势
https://stackoverflow.com/questions/46984069
复制相似问题