Keeping dependencies up to date
40 min · Advanced
Need help? Ask a tutor on WhatsApp (opens in a new tab)ShopLite lists about ten libraries in its pom.xml but runs over a hundred. When a new flaw is announced in one of them, how do you find out whether you use it, and how do you upgrade safely?
Vulnerable components: a library flaw becomes your flaw
A CVE (Common Vulnerabilities and Exposures) id is the public name of one known security flaw, such as CVE-2021-44228 for Log4Shell. Scanners, security notices and update notes all use it to point at the same flaw.
Ask Maven whether ShopLite runs log4j. The answer shows a library that nobody added by hand.
Example 1 · Is log4j in ShopLite? Asking mvn dependency:tree
Runs in: the shoplite-api Spring Boot project
$ mvn dependency:tree -Dincludes=org.apache.logging.log4j,org.apache.tomcat.embed:tomcat-embed-core[INFO] --- dependency:3.10.0:tree (default-cli) @ shoplite-api --- [INFO] com.shoplite:shoplite-api:jar:1.1.0 [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] | \- 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.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] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
What this code does
- ShopLite never names log4j, yet
log4j-apiarrives through the web starter: a transitive dependency. - It is
log4j-apiwith a bridge to SLF4J; Spring Boot logs with Logback. Log4Shell was inlog4j-core, which ShopLite does not use. - Tomcat 11.0.24 comes the same way, chosen by Boot 4.1.1. A Tomcat CVE is fixed by upgrading Boot.
A vulnerable component is a library with a known security flaw. Your app runs the library's code with your app's rights, so its flaw is your flaw, even if you never call the broken method yourself. Most libraries arrive as transitive dependencies: dependencies of your dependencies. ShopLite lists about ten in pom.xml but runs over a hundred. OWASP Top 10 2025 calls this A03 Software Supply Chain Failures.
Log4Shell (CVE-2021-44228, December 2021) is the famous case. The logging library log4j-core, versions 2.0-beta9 to 2.14.1, treated some text inside log messages as an instruction to look up and load code from another server. Apps that logged a user-supplied value, such as a username, could be taken over. It was fixed in 2.15.0 and hardened further in 2.16.0 and 2.17.x.
Spring Boot's managed versions: upgrade through the parent
Dependency management is a list of one tested version for every library Spring Boot knows, such as Tomcat, Jackson, Hibernate and the MySQL driver. The Boot parent supplies it, so starters need no <version>.
The parent's version line in pom.xml is the one ShopLite upgrades. A command shows which MySQL driver version Boot 4.1.1 picks.
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.1.1</version> <!-- upgrade here --></parent><properties> <java.version>17</java.version> <!-- Only for an urgent fix Boot has not shipped yet; remove after the next Boot upgrade --> <!-- <tomcat.version>11.0.25</tomcat.version> --></properties>Example 2 · Which version does Boot pick? Checking a managed version
Runs in: the shoplite-api Spring Boot project
$ mvn help:evaluate -Dexpression=mysql.version -q -DforceStdout9.7.0
What this code does
mysql.versionis the property Boot's dependency management uses formysql-connector-j.- Boot 4.1.1 manages driver 9.7.0, even though the year-numbered 26.x driver line is newer.
- Overriding a property like this is the one-line way to move a single managed library, and the override must be removed later.
So the normal upgrade is one line: raise the parent's version, and every managed library moves together to versions tested with each other. Patch releases (4.1.1 → 4.1.2) mostly carry fixes, including security fixes.
When a flaw is fixed in one library before Boot releases, override just that library with its version property, such as <tomcat.version>, and remove the override after the next Boot upgrade. Never pin a Spring-managed library "just because": you then own its updates.
Seeing your versions: dependency:tree and versions:display-dependency-updates
The Versions Maven Plugin lists which libraries have a newer release, and which of those are only previews.
Example 3 · Outdated dependencies with the Versions Maven Plugin
Runs in: the shoplite-api Spring Boot project
$ mvn versions:display-parent-updates versions:display-dependency-updates$ mvn versions:display-parent-updates versions:display-dependency-updates "-Dmaven.version.ignore=.*-M.*,.*-RC.*"[INFO] --- versions:2.21.0:display-parent-updates (default-cli) @ shoplite-api --- [INFO] The parent project has a newer version: [INFO] org.springframework.boot:spring-boot-starter-parent 4.1.1 -> 4.2.0-M2 [INFO] [INFO] --- versions:2.21.0:display-dependency-updates (default-cli) @ shoplite-api --- [INFO] The following dependencies in Dependencies have newer versions: [INFO] com.mysql:mysql-connector-j .......................... 9.7.0 -> 26.7.0 [INFO] org.springframework.boot:spring-boot-starter-actuator ... [INFO] 4.1.1 -> 4.2.0-M2 ... (with milestones and release candidates ignored) [INFO] --- versions:2.21.0:display-parent-updates (default-cli) @ shoplite-api --- [INFO] The parent project is the latest version: [INFO] org.springframework.boot:spring-boot-starter-parent ......... 4.1.1 [INFO] [INFO] --- versions:2.21.0:display-dependency-updates (default-cli) @ shoplite-api --- [INFO] No dependencies in Dependencies have newer versions. [INFO] [INFO] The following dependencies in Dependency Management have newer versions: [INFO] com.mysql:mysql-connector-j .......................... 9.7.0 -> 26.7.0 [INFO] [INFO] BUILD SUCCESS
What this code does
- The first run suggests 4.2.0-M2, a milestone: a preview for testing, never for production.
- Ignoring
-Mand-RCversions shows the truth: Boot 4.1.1 is the latest stable release, and only the MySQL driver has a newer line. - Your output depends on the day you run it; new releases appear all the time.
mvn dependency:tree prints every library the project uses, with the path that brought it in. With -Dincludes=groupId it shows only the ones you ask about: the quickest answer to "do we use log4j-core?" when a new CVE appears.
The Versions Maven Plugin compares your versions with Maven Central: mvn versions:display-parent-updates checks the Boot parent and mvn versions:display-dependency-updates checks the rest. It also lists milestones such as 4.2.0-M2 (test versions, not for production), so add -Dmaven.version.ignore=.*-M.*,.*-RC.* to see stable versions only.
Vulnerability scanning: OWASP Dependency-Check and Dependabot
CVSS (Common Vulnerability Scoring System) is a score from 0 to 10 for how serious a known flaw is; 7 and above is high. A scanner can fail the build when a flaw scores above the limit you set.
A security-scan Maven profile that runs OWASP Dependency-Check, after the Dependabot file that opens upgrade pull requests.
# .github/dependabot.ymlversion: 2updates: - package-ecosystem: "maven" directory: "/" schedule: interval: "weekly" open-pull-requests-limit: 5 - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly"Example 4 · pom.xml: a security-scan profile with OWASP Dependency-Check
Runs in: the shoplite-api Spring Boot project
<profiles> <!-- mvn -P security-scan verify: checks every library against the NVD list of known vulnerabilities. The first run downloads the NVD data (slow); set NVD_API_KEY for faster updates. --> <profile> <id>security-scan</id> <build> <plugins> <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>13.0.0</version> <configuration> <nvdApiKeyEnvironmentVariable>NVD_API_KEY</nvdApiKeyEnvironmentVariable> <!-- Fail the build for any known vulnerability with CVSS score 7 or more --> <failBuildOnCVSS>7</failBuildOnCVSS> <formats> <format>HTML</format> <format>JSON</format> </formats> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile></profiles>$ mvn help:describe -Dplugin=org.owasp:dependency-check-maven:13.0.0 -Dgoal=check -Ddetail
...
failBuildOnCVSS (Default: 11)
User property: failBuildOnCVSS
...
formats
...
nvdApiKey
User property: nvdApiKey
The NVD API Key. The parameters nvdApiKeyEnvironmentVariable or
nvdApiServerId and nvdApiKeyEnvironmentVariable.What this code does
- The plugin runs only with
-P security-scan, so normal builds do not wait for the NVD download. failBuildOnCVSS7 stops the build for high and critical flaws; the default 11 never fails, because no score is above 10.help:describelists a plugin's real settings: a quick way to check names before you trust a blog post. The key itself stays in an environment variable, never in the pom.
A dependency scanner compares every library you use, transitive ones included, with public lists of known flaws. OWASP Dependency-Check is a free Maven plugin that uses the NVD (the US National Vulnerability Database). The first scan downloads the whole NVD data set, which takes a long time; a free NVD API key makes updates much faster.
ShopLite puts the plugin in a security-scan profile so everyday builds stay quick, and runs mvn -P security-scan verify before a release and in CI. Dependabot is GitHub's bot: with a .github/dependabot.yml file it checks your pom.xml every week and opens a pull request for each update, with the release notes attached.
A safe upgrade routine
Version numbers tell you how careful to be. A small program classifies an upgrade as patch, minor, major or pre-release.
Example 5 · Patch, minor or major? Classifying an upgrade
import java.util.List;
public class UpgradeKindDemo { static int[] parse(String version) { String[] parts = version.split("[.-]"); return new int[] {Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])}; }
static String kind(String from, String to) { if (to.contains("-M") || to.contains("-RC") || to.contains("SNAPSHOT")) { return "pre-release: skip for production"; } int[] a = parse(from); int[] b = parse(to); if (b[0] != a[0]) { return "major: read the migration guide, expect code changes"; } if (b[1] != a[1]) { return "minor: read the release notes, run all tests"; } return b[2] > a[2] ? "patch: usually fixes only, upgrade soon" : "no upgrade"; }
public static void main(String[] args) { List<String[]> upgrades = List.of( new String[] {"4.1.1", "4.1.2"}, new String[] {"4.1.1", "4.2.0"}, new String[] {"4.1.1", "4.2.0-M2"}, new String[] {"3.5.6", "4.1.1"}, new String[] {"11.0.24", "11.0.24"}); for (String[] u : upgrades) { System.out.println(u[0] + " -> " + u[1] + ": " + kind(u[0], u[1])); } }}4.1.1 -> 4.1.2: patch: usually fixes only, upgrade soon 4.1.1 -> 4.2.0: minor: read the release notes, run all tests 4.1.1 -> 4.2.0-M2: pre-release: skip for production 3.5.6 -> 4.1.1: major: read the migration guide, expect code changes 11.0.24 -> 11.0.24: no upgrade
What this code does
- Versions such as 4.1.1 are major.minor.patch; the number that changes tells you how careful to be.
- Pre-releases are recognised first, before the numbers are compared.
- This is the habit in code form: patch upgrades quickly, minor ones with tests, major ones as a planned piece of work.
An upgrade can break things, so do it the same careful way every time. Small and often is safer than one huge jump a year: a patch upgrade rarely breaks anything, a major one (4 → 5) usually needs code changes.
Order of execution
A safe upgrade, step by step
Tap the steps in the order a careful team upgrades Spring Boot.
Next step
Check your understanding
12 quick questions