Table of contents
1.
Introduction
2.
What is Spring Boot Starters?
3.
What is Spring Boot Starter Parent?
4.
Dependency Management Using Starter Parent
5.
How To Override The Default Configurations?
6.
Spring Boot Without Starter Parent
7.
Frequently Asked Questions
7.1.
What are spring boot starters?
7.2.
Why do we need Spring-Boot-starter-parent?
7.3.
What is the difference between Spring Boot starter web and Spring-Boot-starter-parent?
7.4.
What is the difference between Spring Boot starter and Spring Cloud starter?
7.5.
Can we override the default configurations provided by spring-boot-starter-parent?
8.
Conclusion
Last Updated: Oct 24, 2024
Easy

Spring Boot Starter Parent

Author Rajat Agrawal
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Spring Boot Starters are the dependency descriptor that can be included in the project. Spring Boot provides several Starters that can be used to add all the dependencies required for a project.

Spring Boot Starter Parent is one of the starters provided by Spring Boot.

Spring Boot Starter Parent

Let’s understand the Spring Boot Starters with examples.

What is Spring Boot Starters?

As we already discussed in the introduction section, Spring Boot Starters are the dependency descriptor included in the project.

Spring Boot Starters can be added to the pom.xml file of our project as per the project's requirement. You need to add the starters to the pom.xml file, and those starters will automatically provide all the required dependencies.

For example, if we want to create a web application, we need to add spring-boot-starter-web in the pom.xml file. This spring-boot-starter-web itself contains a pom.xml in which all the required dependencies for a web application project are present.

The below starter for spring-boot-starter-web can be added to pom.xml to create a web application:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
You can also try this code with Online Java Compiler
Run Code

 

Only the above starter is required to add to the pom.xml file, and this starter will automatically provide all the web-related dependencies.

Spring Boot provides several Starters that can be used to add all the dependencies required for a project. Let’s now discuss the spring-boot-starter-parent in depth.

You can also consider our Spring Boot Course to give your career an edge over others.

What is Spring Boot Starter Parent?

The spring-boot-starter-parent is one of the starters that Spring Boot provides. It provides default configurations for our applications. It also provides dependency and plugin management for applications built in using Maven.

The spring-boot-starter-parent inherits dependency management from spring-boot-dependencies. And all the other spring boot starters (e.g., spring-boot-starter-web, spring-boot-starter-test, etc.) inherit dependency management and version control from spring-boot-starter-parent.

Whenever we create a spring boot application we can see the spring-boot-starter-parent as a parent pom in the pom.xml.

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/>
</parent>
You can also try this code with Online Java Compiler
Run Code

 

You can see the above code in the following picture:

 

Parent pom allows you to manage the following things for multiple child projects and modules:

1.) Dependency Management: It can manage the different versions of dependencies.

2.) Configuration: What java version is configured, what encoding is configured, and other properties.

3.) Plugin Configuration: It provides the default configuration for maven plugins.


The spring boot starter parent provides the default java version and encoding, which we can see below. The default java version is 1.8 and the default encoding is UTF-8. 

<properties>
    <java.version>1.8</java.version>
    <resource.delimiter>@</resource.delimiter>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
You can also try this code with Online Java Compiler
Run Code


You can see the above properties tag containing the java version and encoding by clicking ctrl+right click on the contents inside the parent tag into the main pom.xml file.

You can see the above code in the following picture:


The other default configuration the spring boot starter parent provides is maven plugins. We have shown some of the default maven plugins below.

<pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.jetbrains.kotlin</groupId>
          <artifactId>kotlin-maven-plugin</artifactId>
          <version>${kotlin.version}</version>
          <configuration>
            <jvmTarget>${java.version}</jvmTarget>
            <javaParameters>true</javaParameters>
          </configuration>
          <executions>
            <execution>
              <id>compile</id>
              <phase>compile</phase>
              <goals>
                <goal>compile</goal>
              </goals>
            </execution>
            <execution>
              <id>test-compile</id>
              <phase>test-compile</phase>
              <goals>
                <goal>test-compile</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <parameters>true</parameters>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <executions>
            <execution>
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <classesDirectory>${project.build.outputDirectory}</classesDirectory>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>${start-class}</mainClass>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              </manifest>
            </archive>
          </configuration>
        </plugin>
    </plugins>
</pluginManagement>
You can also try this code with Online Java Compiler
Run Code

 

By default, all these plugins are added in the parent’s pom.xml file (not the main pom.xml ). You can see these by ctrl+right clicking on the parent tag's contents into the main pom.xml file.

You can see the above code in the following picture:

 

The third important feature that the spring boot starter parent provides is version control for other dependencies. We have shown the version of some of the dependencies below.

<properties>
    <activemq.version>5.16.3</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.93</appengine-sdk.version>
    <artemis.version>2.19.0</artemis.version>
    <aspectj.version>1.9.7</aspectj.version>
    <assertj.version>3.21.0</assertj.version>
    <atomikos.version>4.0.6</atomikos.version>
    <awaitility.version>4.1.1</awaitility.version>
    <build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
    <byte-buddy.version>1.11.22</byte-buddy.version>
    <caffeine.version>2.9.3</caffeine.version>
    <cassandra-driver.version>4.13.0</cassandra-driver.version>
    <classmate.version>1.5.1</classmate.version>
    <commons-codec.version>1.15</commons-codec.version>
    <commons-dbcp2.version>2.9.0</commons-dbcp2.version>
    <commons-lang3.version>3.12.0</commons-lang3.version>
    <commons-pool.version>1.6</commons-pool.version>
    <commons-pool2.version>2.11.1</commons-pool2.version>
    <couchbase-client.version>3.2.4</couchbase-client.version>
    <db2-jdbc.version>11.5.7.0</db2-jdbc.version>
    <dependency-management-plugin.version>1.0.11.RELEASE</dependency-management-plugin.version>
    <derby.version>10.14.2.0</derby.version>
    <dropwizard-metrics.version>4.2.7</dropwizard-metrics.version>
    <ehcache.version>2.10.9.2</ehcache.version>
    <ehcache3.version>3.9.9</ehcache3.version>
    <elasticsearch.version>7.15.2</elasticsearch.version>
    <embedded-mongo.version>3.0.0</embedded-mongo.version>
    <flyway.version>8.0.5</flyway.version>
    <freemarker.version>2.3.31</freemarker.version>
    <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
    <glassfish-el.version>3.0.4</glassfish-el.version>
    <glassfish-jaxb.version>2.3.5</glassfish-jaxb.version>
    <glassfish-jstl.version>1.2.6</glassfish-jstl.version>
    <groovy.version>3.0.9</groovy.version>
</properties>
You can also try this code with Online Java Compiler
Run Code

 

You can see this properties tag containing the version in the spring-boot-dependencies pom.xml. To see this, click ctrl+right click on the contents inside the parent tag into the main pom.xml file, and after that, a new file parent pom.xml will open. Now, click ctrl+right click on the contents inside the parent tag into the parent’s pom.xml file.

You can see the above code in the following picture:

 

Let’s now look into some other important features provided by spring-boot-starter-parent.

Dependency Management Using Starter Parent

Once the starter parent is added to our project, we can pull any dependency from the parent by just declaring it in our dependencies tag.

Also, we don't need to worry about the versions of the dependencies, and Maven will download the jar files based on the version defined for the starter parent in the parent tag.

For example, if we're building a web project, we can add spring-boot-starter-web directly into the pom.xml, and we don't need to specify the version:

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
</dependencies>
You can also try this code with Online Java Compiler
Run Code


Sometimes we need a different version of a particular dependency; in that case, we need to explicitly mention the version of that dependency in the dependencyManagement section.

For example, if we need a spring-boot-starter-web with a version greater/lower than the version provided by the starter parent. We can add the version tag and mention the version as follows:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.4.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>
You can also try this code with Online Java Compiler
Run Code

How To Override The Default Configurations?

We know that spring-boot-starter-parent configures the java compiler version, plugins version, and Dependencies version using the properties defined inside it. Under the properties section, we can override those property values inside the pom.xml file.

Suppose we want to use the java compiler version 11 other than the default version 1.8 provided by the starter parent. We can specify the version inside the pom.xml file under the properties section. Like below.

<properties>
<java.version>11</java.version>
</properties>
You can also try this code with Online Java Compiler
Run Code

 

Note: To override the properties of individual dependencies, we need to add those dependencies before the addition of spring-boot-dependencies.

Spring Boot Without Starter Parent

Sometimes we want to inherit from the custom parent POM or want to define all the Maven configurations manually; in that case, we don’t inherit from the spring-boot-starter-parent pom. But, we can still benefit from its dependency tree by adding a dependency spring-boot-dependencies in our project in import scope.

This can be added as follows:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.5.2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
You can also try this code with Online Java Compiler
Run Code

Also See, spring mvc vs spring boot

Frequently Asked Questions

What are spring boot starters?

Spring Boot Starters are the dependency descriptor that can be included in the project. Spring Boot provides several Starters that can be used to add all the dependencies required for a project.

Why do we need Spring-Boot-starter-parent?

Spring-Boot-starter-parent simplifies dependency management by providing a default set of configurations for a Spring Boot project. It helps manage versions of dependencies, avoids conflicts, and provides common plugin configurations, reducing manual setup for developers.

What is the difference between Spring Boot starter web and Spring-Boot-starter-parent?

Spring Boot Starter Web is a dependency for building web applications, including RESTful services. Spring-Boot-starter-parent is a parent POM that simplifies dependency and plugin management for Spring Boot projects, setting default versions and configurations.

What is the difference between Spring Boot starter and Spring Cloud starter?

Spring Boot Starter is used to bootstrap basic Spring Boot applications, focusing on standalone app features. Spring Cloud Starter is tailored for distributed systems, providing tools for cloud-based microservices, such as service discovery, configuration, and circuit breakers.

Can we override the default configurations provided by spring-boot-starter-parent?

Yes, the default configurations can be overridden inside the pom.xml file under the properties section. 

Conclusion

In this blog, we explored Spring Boot Starters, including the Spring Boot Starter Parent. We discussed its key features and how it simplifies dependency management by providing default configurations and managing versions. Additionally, we highlighted how the Starter Parent helps developers avoid conflicts and streamline project setup, making Spring Boot development more efficient.

Live masterclass