June 21, 2022

spring-boot-starter-parent in Spring Boot

In this post we’ll learn about spring-boot-starter-parent and how it helps in quick and easy Spring Boot development by providing useful Maven defaults and dependency management. We’ll also see how to override default dependencies provided by Spring Boot Starter Parent.

Spring-boot-starter-parent configuration

Mostly all Spring Boot projects using Maven as build tool inherit from the spring-boot-starter-parent project to obtain sensible defaults.

To configure your Spring Boot project to inherit from the spring-boot-starter-parent, in your pom.xml set the parent as follows:

<!-- Inherit defaults from Spring Boot -->

Spring Boot starter parent provides the following features-

  1. Compatible Java version as the default compiler level. For Spring Boot 2.1.6 release Java 1.8 is the default.
  2. UTF-8 source encoding.
  3. Dependency Management- This section is inherited from the spring-boot-dependencies pom and it manages the versions of common dependencies. This dependency management provides a curated list of dependencies that it supports so that you do not need to provide a version for any of these dependencies in your build configuration, Spring Boot manages that for you. The curated list contains all the spring modules that you can use with Spring Boot as well as a refined list of third party libraries. The list is available as a standard Bills of Materials (BOM) manifests (spring-boot-dependencies).
  4. Execution of spring-boot:repackage goal which repackages existing JAR and WAR archives so that they can be executed from the command line using java -jar.

Spring-boot-starter-parent composition

spring-boot-starter-parent itself inherits from spring-boot-dependencies, given below is the part of pom.xml for spring-boot-starter-parent you can get the complete configuration here- https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml

<name>Spring Boot Starter Parent</name>
<description>Parent pom providing dependency and plugin management for applications built with Maven</description>
  <resource.delimiter>@</resource.delimiter> <!-- delimiter that doesn't clash with Spring ${} placeholders -->

In the properties section of this pom.xml you can see the configuration for Java version and UTF encoding.

But it is spring-boot-dependencies which provides the curated list of dependencies, in the properties section of pom.xml for spring-boot-dependencies you can see the default version for various dependencies. Complete pom.xml here- https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml

  <!-- Dependency versions -->


Overriding dependency version in spring-boot-starter-parent

As we have seen spring-boot-dependencies provides a list of compatible default dependencies for the Spring Boot version used. If you want to change the version of any dependency then you can define the version in the property section of pom.xml used in your project.

For example default versions for mongodb and log4j2 in spring-boot-dependencies are as following-


If you want to provide different version then in the properties section of your Spring Boot project’s pom.xml change it as given below.


Using Spring Boot without the Parent POM

If you do not want to inherit from spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency, as follows:

      <!-- Import dependency management from Spring Boot -->

That's all for the topic spring-boot-starter-parent in Spring Boot. If something is missing or you have something to share about the topic please write a comment.

You may also like

No comments:

Post a Comment