Why is spring-boot-dependencies in dependencyManagement?
Solution 1
It's definitely correct. Please see Using Spring Boot without the parent POM!
Solution 2
So why is spring-boot-dependencies to be included as dependencyManagement?
Let's say you have a project named projectA
and you add the spring-boot-dependencies
to the dependencyManagement
section in your 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>
If you notice closely, you will find that all the Spring Boot dependencies declared under the dependencies
section don't need to specify the version
. It derives the version
from the version of spring-boot-dependencies
specified in the dependencyManagement
section.
Advantages of Dependency Management
It centralizes dependency information by specifying the Spring Boot version at one place. It really helps during upgrade from one version to another.
Subsequent declaration of Spring Boot dependencies just mentions the library name without any version. Especially helpful in multi-module projects
It avoids mismatch of different versions of spring boot libraries in a project.
No Conflicts.
rwfbc
Updated on June 05, 2022Comments
-
rwfbc almost 2 years
The Spring documentation Using Spring Boot without the parent POM shows that the dependency on
spring-boot-dependencies
is added to thedependencyManagement
section. Is this really correct?spring-boot-dependencies specifies version properties for all the dependencies. However, these properties are not available in the POM that uses
spring-boot-dependencies
. Presumably, this is becausespring-boot-dependencies
is independencyManagement
.spring-boot-dependencies only includes
dependencyManagement
andpluginManagement
. So it seems possible to includespring-boot-dependencies
as a dependency (not dependencyManagement) without adding unnecessary dependencies.So why is
spring-boot-dependencies
to be included asdependencyManagement
?