Configuring SpringBoot starter parent dependency

If you open a Spring Boot project, you will see that at the top they all use a spring-boot-starter-parent as the parent in pom.xml.

<parent> 	<groupId>org.springframework.boot</groupId> 	<artifactId>spring-boot-starter-parent</artifactId> 	<version>2.1.0.RELEASE</version> 	<relativePath/>   </parent>

Parent Poms allow you to manage several aspects for the child projects such as:

  • Dependency Management – Version of dependencies
  • Configuration – Java Version and Other Properties
  • Default Plugin Configuration

A look inside Spring Boot Starter Parent

Spring Boot Starter Parent defines spring-boot-dependencies as the parent pom. It inherits dependency management from spring-boot-dependencies. Details in the next section.

<parent> 	<groupId>org.springframework.boot</groupId> 	<artifactId>spring-boot-dependencies</artifactId> 	<version>${revision}</version> 	<relativePath>../../spring-boot-dependencies</relativePath> </parent>

The Parent pom goes on defining a list of properties such as:

<properties> 	<main.basedir>${basedir}/../../..</main.basedir> 	<java.version>1.8</java.version> 	<resource.delimiter>@</resource.delimiter>  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 	<maven.compiler.source>${java.version}</maven.compiler.source> 	<maven.compiler.target>${java.version}</maven.compiler.target> </properties>

A project can override this by specifying again the property, for example:

<java.version>1.9</java.version> 

How to override default dependency version?

The actual version for all dependencies is stored in the spring-boot-project/spring-boot-dependencies/pom.xml. Here is an excerpt of it:

<properties> 	<activemq.version>5.15.7</activemq.version> 	<antlr2.version>2.7.7</antlr2.version> 	<appengine-sdk.version>1.9.67</appengine-sdk.version> 	<artemis.version>2.6.3</artemis.version> 	<aspectj.version>1.9.2</aspectj.version> 	<assertj.version>3.11.1</assertj.version> 	<atomikos.version>4.0.6</atomikos.version> 	<bitronix.version>2.1.4</bitronix.version> 	<byte-buddy.version>1.9.3</byte-buddy.version> 	<caffeine.version>2.6.2</caffeine.version> 	<cassandra-driver.version>3.6.0</cassandra-driver.version> 	<classmate.version>1.4.0</classmate.version> 	<commons-codec.version>1.11</commons-codec.version> 	<commons-dbcp2.version>2.5.0</commons-dbcp2.version> 	<commons-lang3.version>3.8.1</commons-lang3.version>         <commons-pool.version>1.6</commons-pool.version>

Therefore, if you wanted to override the default version of a dependency, you can just provide this information in properties tag like this:

<properties>    <activemq.version>5.15.1</activemq.version> </properties>
Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon