Why is spring-boot-dependencies in dependencyManagement?

10,210

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.

Share:
10,210
rwfbc
Author by

rwfbc

Updated on June 05, 2022

Comments

  • rwfbc
    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 the dependencyManagement 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 because spring-boot-dependencies is in dependencyManagement.

    spring-boot-dependencies only includes dependencyManagement and pluginManagement. So it seems possible to include spring-boot-dependencies as a dependency (not dependencyManagement) without adding unnecessary dependencies.

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