Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 66 ยท Getting Started

Starters and Dependency Management

What a Spring Boot starter is, how the BOM manages versions, how to override a version, exclude a transitive dependency and read the dependency tree.

A typical Java web application needs dozens of libraries: a web server, a web framework, a JSON mapper, a logging backend, validation, a database driver, a test framework. Choosing them is one problem; making sure their versions work together is a worse one. Before Boot, "dependency hell" (a library that needs version 2 while another needs version 1) ate days of every project.

Spring Boot solves this with two ideas. Starters are single dependencies that stand for a whole capability. A BOM (bill of materials) fixes the version of every library so they are known to work together. In this lesson you will learn what is inside a starter, how versions are managed, how to override one safely, how to exclude something you do not want and how to read the dependency tree. Maven and Gradle cannot run in our sandbox, so build snippets are read-only; two TryIt blocks model the resolution logic in plain Java.

What a starter is

A starter contains no code of its own. It is just a build file (a POM) whose job is to list other dependencies. When you add spring-boot-starter-webmvc to your project, Maven or Gradle also downloads everything that starter lists, and everything those libraries list, and so on. These indirect dependencies are called transitive dependencies.

A starter is a shopping list

One line You add a single dependency to your build.
Many libraries It pulls in a tested set of libraries.
Compatible Versions come from the Boot BOM.
1 / 2

Typical contents, simplified (exact lists differ slightly by Boot version):

  • spring-boot-starter is the core every other starter includes: Spring Boot itself, auto-configuration, logging with Logback and YAML parsing.
  • Web starter (spring-boot-starter-webmvc in Boot 4, spring-boot-starter-web in Boot 3): Spring MVC, an embedded Tomcat and Jackson for JSON.
  • spring-boot-starter-data-jpa: Spring Data JPA, Hibernate and the HikariCP connection pool. You add the database driver yourself.
  • spring-boot-starter-validation: Hibernate Validator, the reference implementation of Bean Validation. It is separate from the web starter, so a missing @Valid effect is often just a missing dependency.
  • spring-boot-starter-test: JUnit Jupiter, AssertJ, Mockito, JSONassert, JsonPath and Spring's test support. You add it with test scope.

Starters follow a naming rule: official ones are spring-boot-starter-<name>. Third parties use <name>-spring-boot-starter, so a library's starter never looks like an official one. You will write your own in Writing Your Own Starter.

A starter only provides the libraries. Whether they are configured is the job of auto-configuration, which looks at what is on the classpath (How Auto-Configuration Works). Adding a starter is therefore the way you ask for a feature.

The BOM and managed versions

Look at a dependency block again:

XML
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

There is no <version>. The version comes from the Spring Boot dependencies BOM (spring-boot-dependencies), a POM that lists a tested version for hundreds of libraries: Spring modules, Hibernate, Jackson, Tomcat, Mockito, Flyway, Micrometer and many drivers. Every Boot release ships its own BOM, so choosing a Boot version chooses the versions of everything else.

You get the BOM in one of three ways:

XML
<!-- 1. Maven: inherit from the parent (what Initializr generates) -->
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>4.0.0</version>
</parent>

<!-- 2. Maven: import the BOM when you already have another parent -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>4.0.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
GROOVY
// 3. Gradle: the dependency-management plugin imports the BOM
plugins {
    id 'org.springframework.boot' version '4.0.0'
    id 'io.spring.dependency-management' version '1.1.7'
}

The benefit is large: you upgrade Boot by changing one version number, and every managed library moves to a combination the Spring team has tested together.

The next TryIt models this. A tiny BOM maps library names to versions, a starter graph lists what depends on what, and a resolver prints the dependency tree with versions filled in. Starters and versions here are made up for the demo.

Java Resolving a dependency tree

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Real tools do the same walk. The command that prints the actual tree for your project is the single most useful dependency command:

TEXT
./mvnw dependency:tree
./gradlew dependencies --configuration runtimeClasspath

When two paths in the tree ask for different versions of the same library, Maven applies "nearest definition wins" and Gradle picks the highest version. With the BOM in place, the managed version wins and the conflict mostly disappears. That is another reason to keep the BOM.

Overriding a managed version

Sometimes you must differ from the BOM, for example to pick up a security fix before the next Boot release. The BOM defines a version property for each managed library, and you override the property, not the dependency. In Maven (read-only):

XML
<properties>
  <java.version>21</java.version>
  <postgresql.version>42.7.8</postgresql.version>
</properties>

In Gradle with the dependency-management plugin:

GROOVY
ext['postgresql.version'] = '42.7.8'

The property names are listed in the reference documentation ("Dependency Versions"). Overriding works because every place that uses the library reads the same property.

Be careful. Libraries in the BOM were tested together, and a newer version of one may break another. Override one library at a time, run your tests, and remove the override when a later Boot release catches up. A setting you forgot is a quiet source of "works on my machine" bugs.

You can also give a version explicitly on one dependency. That wins over the BOM too, but only for that one declaration, so transitive uses elsewhere still see the old version. Prefer the property.

Excluding transitive dependencies

If a starter brings something you do not want, exclude it. The classic example is swapping the embedded server: the web starter includes Tomcat, so to use Jetty you exclude the Tomcat starter and add the Jetty one (read-only; check the names for your Boot version):

XML
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webmvc</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

In Gradle:

GROOVY
configurations {
    implementation {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
}

This works because auto-configuration reacts to what is on the classpath: no Tomcat classes, Jetty classes present, so the Jetty web server is configured. Replacing the logging backend (exclude spring-boot-starter-logging, add the Log4j2 starter) follows the same pattern.

Use exclusions sparingly. Each one is a place where your project differs from the tested default, and every exclusion deserves a comment saying why.

Dependency scopes

Not every dependency belongs in the final jar. Common scopes (Maven names, with Gradle equivalents):

Maven scope Gradle configuration Meaning
compile (default) implementation Needed to compile and run
runtime runtimeOnly Needed only when running, for example a JDBC driver
test testImplementation Only for tests, such as spring-boot-starter-test
provided compileOnly Supplied by the environment, for example a servlet container
optional developmentOnly (similar idea) Used here but not passed on, such as DevTools

Putting each dependency in the narrowest scope keeps the production jar small and avoids shipping test libraries.

The second TryIt shows the order in which a version is chosen, from an explicit declaration down to the BOM. It is a stand-in for what Maven and Gradle do, but it makes the precedence concrete.

Java Which version wins?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The last line mirrors a real build error you will see: a library that no BOM manages needs an explicit version.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a Spring Boot starter contain?

    A starter has no code of its own. It exists to bring in a tested set of libraries with a single dependency.
  2. 2. Why can you omit the version of spring-boot-starter-data-jpa in a Boot project?

    The BOM (inherited from the parent or imported) lists a tested version for each managed library.
  3. 3. What is the recommended way to use a newer managed library version, such as a security fix?

    The BOM defines one version property per library. Overriding the property changes every use of that library consistently.
  4. 4. You want Jetty instead of Tomcat. What do you do?

    Auto-configuration reacts to the classpath. Without Tomcat and with Jetty present, Boot configures the Jetty server.

Summary

  • A starter is a dependency-only POM that stands for a capability; official ones are named spring-boot-starter-*.
  • The BOM (via spring-boot-starter-parent, an imported spring-boot-dependencies, or the Gradle plugin) supplies tested versions, so starters need none.
  • Upgrade Boot by changing one version and the managed libraries move together.
  • Override a managed version through its version property, one library at a time, and remove the override once Boot catches up.
  • Exclude transitive dependencies only when needed, for example Tomcat for Jetty; auto-configuration follows the classpath.
  • Inspect the real result with ./mvnw dependency:tree or ./gradlew dependencies.

Next: IoC and Dependency Injection.