English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SpringBoot Dependency Management

Spring Boot automatically manages dependencies and configurations. Each Spring Boot version provides a list of dependencies it supports. The dependency list can be checked with Maven Used together Material listPart of (Spring Boot dependencies). Therefore, we do not need to specify the version of the dependencies in the configuration. Spring Boot manages them automatically. When we update the Spring Boot version, Spring Boot will automatically upgrade all dependencies in a consistent manner.

Advantages of dependency management

Provide centralized dependency information by specifying a Spring Boot version in one place. It will be helpful when switching from one version to another. It avoids mismatches between different versions of Spring Boot libraries. We just need to write a library name and specify the version. It is very useful in multi-module projects.

Note: If necessary, Spring Boot can also override the version of dependencies.

Maven dependency management system

Maven project from spring-boot-starter-parent inherits the following features:

default Java compiler version UTF-8 source encoding it gets from spring-boot-dependency-pom inherits a Dependency Section .It manages the versions of common dependencies. For this dependency, it will ignore  tag. from spring-boot-dependencies that are inherited from the POM of dependencies intelligentresource filtering intelligentplugin configuration

Inherit Starter Parent

When configuring the project, the following spring-boot-starter-parent will be automatically inherited.

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.BUILD-SNAPSHOT</version>      <!-- lookup parent from repository -->
<relativePath/> 
</parent>
Note: In the above dependencies, we only specify the Spring Boot version. If you want to add other starters, just deletetag. Similarly, we can also override personal dependencies by overriding properties in the project.

For example, if you want to add another dependency with the same artifact as the one injected, inject the dependency again <properties>tag to override

to change the Java version

We can also use <java.version>Use the tag to change the Java version.

<properties>  
<java.version>1.8</java.version>  
</properties>

Add Spring Boot Maven plugin

We can also add pom.xml file Add Maven plugin.It will package the project into an executable jar in the file.

<build>  
<plugins>  
<plugin>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-maven-plugin</artifactId>  
</plugin>  
</plugins>  
</build>

Spring Boot without parent POM

If we do not want to use spring-boot starter-parent If we want to adopt the advantages of dependency management while still using dependencies, we can use  Tags, as shown below:

Note: It does not maintain plugin management.
<dependencyManagement>
<dependencies>
<dependency><!-- dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

The above dependencies do not allow overrides. To achieve overrides, we need to import  marked spring-boot-dependencies entry, add an entry before the

For example, to upgrade another spring-data-releasetrain , add the following dependencies to the pom.xml file.

<dependencyManagement>
<dependencies>
!--Override Spring Data release train-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain/artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>