Starters and dependency management
40 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)A web app needs dozens of libraries, and one wrong version breaks it only when it runs. Nobody wants to pick every jar and version by hand for a shop API.
Starters: one dependency for one job
A starter is one Maven dependency that brings a tested set of libraries for one job. For example, spring-boot-starter-webmvc brings Spring MVC, Jackson for JSON, an embedded Tomcat server and logging.
The pom.xml of a small practice project, boot-lab: two starters and no library versions.
Example 1 · pom.xml (boot-lab)
Runs in: the boot-lab practice project (Spring Boot 4.1)
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.1.1</version> <relativePath/> </parent> <groupId>com.shoplite</groupId> <artifactId>boot-lab</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot-lab</name> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webmvc-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>> .\mvnw package ... [INFO] Building jar: C:\Users\asha\boot-lab\target\boot-lab-0.0.1-SNAPSHOT.jar ... [INFO] BUILD SUCCESS
What this code does
- Two dependencies, and neither has a
<version>.spring-boot-starter-webmvcis everything a web app needs;spring-boot-starter-webmvc-testis everything its tests need (<scope>test</scope>keeps it out of the app). - The
<parent>is the only place a Spring Boot version appears:4.1.1. Every library version comes from it, as the third section shows. - Run
./mvnw package(on Windows PowerShell write.\mvnw package). The jar it builds already contains a web server, the subject of the Embedded Tomcat lesson.
Without starters you would list each jar yourself. In the JDBC section you added the MySQL driver and HikariCP one by one; a web app needs ten times as many, and one wrong version gives errors such as NoSuchMethodError that only appear when the app runs.
The examples in this module run in boot-lab, so shoplite-api stays clean until the module project. Create it on start.spring.io like shoplite-api: Maven, Java 17, Spring Boot 4.1.x, artifact boot-lab, package name com.shoplite.lab, dependency Spring Web. Its main class is BootLabApplication.
spring-boot-starter-<job>. A library whose name is xyz-spring-boot-starter is a starter written by someone outside the Spring team.The starters ShopLite uses
Two more starters for boot-lab: validation and actuator, again with no version.
Example 2 · pom.xml: adding the validation and actuator starters
Runs in: the boot-lab practice project (Spring Boot 4.1)
<!-- inside <dependencies>, next to the webmvc starter --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency>> ./mvnw dependency:tree -Dincludes=org.hibernate.validator ... [INFO] com.shoplite:boot-lab:jar:0.0.1-SNAPSHOT [INFO] \- org.springframework.boot:spring-boot-starter-validation:jar:4.1.1:compile [INFO] \- org.springframework.boot:spring-boot-validation:jar:4.1.1:compile [INFO] \- org.hibernate.validator:hibernate-validator:jar:9.1.3.Final:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
What this code does
- Two blocks, no versions. After saving the pom, the command
dependency:tree -Dincludes=org.hibernate.validatorkeeps only the branch that leads to that group. - Hibernate Validator 9.1.3 is the library that checks rules such as "price must be positive". The validation starter brought it, through Boot's own
spring-boot-validationmodule. - You never typed
9.1.3.Final. The version came from the Boot parent, so it is the one Boot 4.1.1 was tested with.
ShopLite uses these starters, each with its own test starter, added in this module's project:
spring-boot-starter-webmvc: REST controllers, JSON, embedded Tomcat. Older tutorials call itspring-boot-starter-web; in Boot 4 that name still works but is deprecated.spring-boot-starter-validation: Bean Validation rules such as@NotBlankon request data.spring-boot-starter-jdbc: the HikariCP connection pool and Spring'sJdbcTemplateandJdbcClient. The MySQL driver (mysql-connector-j) is added next to it.spring-boot-starter-actuator: health checks such as/actuator/health.- Test starters: Boot 4 has one per feature, for example
spring-boot-starter-webmvc-testandspring-boot-starter-jdbc-test. Each brings JUnit 5, AssertJ, Mockito and the testing support for its feature.
The parent's managed versions: why there is no <version>
A BOM (bill of materials) is a pom that holds only library versions. Boot's BOM is spring-boot-dependencies, and spring-boot-starter-parent imports it, so Maven uses its version whenever a dependency has no <version>.
A few lines from the real Boot 4.1.1 BOM, and what happens when a library is or is not in it.
Example 3 · Inside the BOM, and asking Maven for a managed version
Runs in: the boot-lab practice project (Spring Boot 4.1)
<!-- a few lines from spring-boot-dependencies-4.1.1.pom --><hikaricp.version>7.0.2</hikaricp.version><hibernate-validator.version>9.1.3.Final</hibernate-validator.version><jackson-bom.version>3.1.5</jackson-bom.version><junit-jupiter.version>6.0.3</junit-jupiter.version><mysql.version>9.7.0</mysql.version><spring-framework.version>7.0.9</spring-framework.version><tomcat.version>11.0.24</tomcat.version>> ./mvnw -q help:evaluate -Dexpression=mysql.version -DforceStdout 9.7.0 > ./mvnw -q help:evaluate -Dexpression=tomcat.version -DforceStdout 11.0.24
What this code does
- These are real lines from the Boot 4.1.1 BOM.
help:evaluateprints the value of one Maven property as your project sees it, here two of those version properties. - Your project never defines them: they arrive through the parent. The same property names are what you set when you need to override a version (last section).
Example 4 · A library Boot does not manage needs its own version
Runs in: the boot-lab practice project (Spring Boot 4.1)
<!-- inside <dependencies> --><dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId></dependency>> ./mvnw package [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] 'dependencies.dependency.version' for com.google.guava:guava:jar is missing. @ line 37, column 21 @ [ERROR] The build could not read 1 project -> [Help 1] ...
What this code does
- Guava (a Google utility library) is not in Boot's list of managed libraries, so Maven has no version to use and stops before compiling anything. The line and column point at the
<dependency>in your ownpom.xml. - The fix is to write the version yourself:
<version>33.5.0-jre</version>. Thendependency:tree -Dincludes=com.google.guavashowsguava:jar:33.5.0-jre:compile. - Rule of thumb: no version for Spring and the libraries Boot manages (Jackson, Tomcat, the MySQL driver, JUnit...), an explicit version for everything else.
The BOM is a list of Maven properties, one per library, well over a hundred in all. Because the parent brings them in, a pom.xml says what the app needs and Boot decides which versions.
The benefit is one upgrade switch. Change the parent from 4.1.1 to the next 4.1.x release and Spring, Jackson, Tomcat, the MySQL driver and the test libraries all move together to versions the Spring team tested side by side.
Predict the output
Which version does Maven use?
Read each pom snippet and pick what the build does.
Round 1 of 2
Boot 4.1.1 manages MySQL 9.7.0. Which driver version is used?
Seeing what you really got: dependency:tree
A transitive dependency is a jar your project does not declare itself but gets because a declared dependency needs it. mvnw dependency:tree prints the declared and the transitive jars as one tree.
The command that prints every jar in the project, and the real tree of boot-lab.
./mvnw dependency:tree./mvnw dependency:tree -Dincludes=org.apache.tomcat.embedExample 5 · The full tree of boot-lab
Runs in: the boot-lab practice project (Spring Boot 4.1)
./mvnw dependency:tree[INFO] --- dependency:3.10.0:tree (default-cli) @ boot-lab --- [INFO] com.shoplite:boot-lab:jar:0.0.1-SNAPSHOT [INFO] +- org.springframework.boot:spring-boot-starter-webmvc:jar:4.1.1:compile [INFO] | +- org.springframework.boot:spring-boot-starter:jar:4.1.1:compile [INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:4.1.1:compile [INFO] | | | +- ch.qos.logback:logback-classic:jar:1.5.38:compile [INFO] | | | | \- ch.qos.logback:logback-core:jar:1.5.38:compile [INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.25.5:compile [INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.25.5:compile [INFO] | | | \- org.slf4j:jul-to-slf4j:jar:2.0.18:compile [INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:4.1.1:compile [INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:3.0.0:compile [INFO] | | \- org.yaml:snakeyaml:jar:2.6:compile [INFO] | +- org.springframework.boot:spring-boot-starter-jackson:jar:4.1.1:compile [INFO] | | \- org.springframework.boot:spring-boot-jackson:jar:4.1.1:compile [INFO] | | \- tools.jackson.core:jackson-databind:jar:3.1.5:compile [INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.21:compile [INFO] | | \- tools.jackson.core:jackson-core:jar:3.1.5:compile [INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:4.1.1:compile [INFO] | | +- org.springframework.boot:spring-boot-starter-tomcat-runtime:jar:4.1.1:compile [INFO] | | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:11.0.24:compile [INFO] | | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:11.0.24:compile [INFO] | | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:11.0.24:compile [INFO] | | \- org.springframework.boot:spring-boot-tomcat:jar:4.1.1:compile [INFO] | +- org.springframework.boot:spring-boot-http-converter:jar:4.1.1:compile [INFO] | | +- org.springframework.boot:spring-boot:jar:4.1.1:compile [INFO] | | | \- org.springframework:spring-context:jar:7.0.9:compile [INFO] | | \- org.springframework:spring-web:jar:7.0.9:compile [INFO] | | +- org.springframework:spring-beans:jar:7.0.9:compile [INFO] | | \- io.micrometer:micrometer-observation:jar:1.17.1:compile [INFO] | | \- io.micrometer:micrometer-commons:jar:1.17.1:compile [INFO] | \- org.springframework.boot:spring-boot-webmvc:jar:4.1.1:compile [INFO] | +- org.springframework.boot:spring-boot-servlet:jar:4.1.1:compile [INFO] | \- org.springframework:spring-webmvc:jar:7.0.9:compile [INFO] | +- org.springframework:spring-aop:jar:7.0.9:compile [INFO] | \- org.springframework:spring-expression:jar:7.0.9:compile [INFO] \- org.springframework.boot:spring-boot-starter-webmvc-test:jar:4.1.1:test [INFO] +- org.springframework.boot:spring-boot-starter-jackson-test:jar:4.1.1:test [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:4.1.1:test [INFO] | +- org.springframework.boot:spring-boot-test:jar:4.1.1:test ... [INFO] | +- org.assertj:assertj-core:jar:3.27.7:test ... [INFO] | +- org.junit.jupiter:junit-jupiter:jar:6.0.3:test ... [INFO] | +- org.mockito:mockito-core:jar:5.23.0:test ... [INFO] +- org.springframework.boot:spring-boot-webmvc-test:jar:4.1.1:test [INFO] | \- org.springframework.boot:spring-boot-web-server:jar:4.1.1:compile [INFO] \- org.springframework.boot:spring-boot-resttestclient:jar:4.1.1:test [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
What this code does
- Two lines in
pom.xmlbecame about 60 jars. The first level (+-and\-right under the project) is what you asked for; everything deeper is what those starters asked for. - Reading one branch: webmvc → starter-tomcat → starter-tomcat-runtime →
tomcat-embed-core11.0.24. That is the web server inside your app. - The last word on each line is the scope.
compilejars go into the app;testjars are only on the class path when tests run. Maven prints each jar once:spring-boot-web-serverappears under the test branch but is markedcompile, because the app's own jars need it too.
Read the tree top down. +- and \- start a child (\- is the last child), | continues a branch, and each line ends with group:artifact:jar:version:scope. When the same library is wanted twice, Maven keeps the copy nearest the top and shows it only once.
Use it whenever you ask "which version of X do I have?" or "where does this jar come from?". -Dincludes=group or -Dincludes=group:artifact trims the output to the branches that lead to one library.
.\mvnw, and wrap any -D... argument in double quotes, otherwise PowerShell splits it at the dot and Maven gets a broken argument.Overriding a managed version, and why to avoid it
A managed version is the library version that Boot's BOM fixes for you, so a dependency needs no <version>. You can replace it with Boot's version property, such as <mysql.version>, in your own <properties>.
Setting mysql.version so the driver is 9.4.0 instead of Boot's 9.7.0, still with no <version> tag.
Example 6 · Overriding the MySQL driver version with a property
Runs in: the boot-lab practice project (Spring Boot 4.1)
<properties> <java.version>17</java.version> <mysql.version>9.4.0</mysql.version></properties><!-- inside <dependencies>, still without a version --><dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope></dependency>> ./mvnw dependency:tree -Dincludes=com.mysql ... [INFO] com.shoplite:boot-lab:jar:0.0.1-SNAPSHOT [INFO] \- com.mysql:mysql-connector-j:jar:9.4.0:runtime [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
What this code does
- Without the
mysql.versionline the tree showsmysql-connector-j:jar:9.7.0:runtime, Boot 4.1.1's choice. With it, Maven uses 9.4.0 and the dependency still has no<version>tag. runtimescope: the driver is needed when the app runs, but your code never imports its classes (it talks tojava.sqlinterfaces), so it is not on the compile class path.- Remove the override once you no longer need it, or it silently pins the old version through every future Boot upgrade.
There are real reasons: a security fix for Tomcat ships before the next Boot release, or your college lab server needs an older driver. Use the property, never a <version> tag on a Boot-managed dependency, so the BOM still manages everything else.
The risk is leaving the tested set. A newer Jackson or Hibernate Validator than Boot expects can fail at runtime with NoSuchMethodError or ClassNotFoundException, far from the pom line that caused it. Prefer upgrading the Boot parent to the next patch release; override only with a comment saying why, and remove it later.
Next step
Check your understanding
11 quick questions