If you’re using Spring Boot 3.4.1 and trying to upgrade Logback to version 1.5.13, you might find that Spring Boot’s default dependencies still pull in Logback 1.5.12. This can be frustrating, especially when dependency exclusions and overrides don’t seem to work as expected.
This guide will walk you through the exact steps needed to force Logback 1.5.13 in your Spring Boot project.
Issue: Spring Boot Forces Logback 1.5.12
By default, Spring Boot 3.4.1 brings in Logback 1.5.12 as a transitive dependency via spring-boot-starter-logging
. Even if you try to exclude or override the version using dependencyManagement
, you might still see Logback 1.5.12 in your dependency tree.
Example from mvn dependency:tree
:
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.4.1:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.4.1:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:3.4.1:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:3.4.1:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:3.4.1:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.5.12:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.5.13:compile
The issue here is that while logback-core is at 1.5.13, logback-classic remains stuck at 1.5.12.
Solution: Override logback-classic
Version
To ensure both logback-classic
and logback-core
use version 1.5.13, follow these steps:
Step 1: Add Logback Dependencies with the Correct Version
Modify your pom.xml
to explicitly include both logback-classic and logback-core at version 1.5.13:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.13</version>
</dependency>
Step 2: Exclude Logback from Spring Boot Starter Web
Spring Boot includes logback-classic 1.5.12 through spring-boot-starter-logging
, so you must exclude it:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Since spring-boot-starter-web includes spring-boot-starter-logging, excluding it ensures that Logback 1.5.12 is not brought in transitively.
Step 3: Add a Separate Logging Starter
Since we excluded spring-boot-starter-logging
, we must manually add the correct logging dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<scope>provided</scope>
</dependency>
OR, if you only want Logback:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.13</version>
</dependency>
Step 4: Run Dependency Check and Verify
After applying these changes, run the following command to confirm Logback 1.5.13 is being used:
mvn dependency:tree | grep logback
You should now see:
[INFO] +- ch.qos.logback:logback-core:jar:1.5.13:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.5.13:compile
If you still see 1.5.12, try running:
mvn clean install -U
to force Maven to update dependencies.
Conclusion
Forcing Logback 1.5.13 in a Spring Boot 3.4.1 project requires overriding both logback-classic
and logback-core
versions. You should:
✔ Explicitly declare logback-classic
and logback-core
at version 1.5.13
✔ Exclude spring-boot-starter-logging
from spring-boot-starter-web
✔ Manually include logging dependencies
✔ Verify the version using mvn dependency:tree
By following these steps, you can successfully force Logback 1.5.13 and avoid conflicts with Spring Boot’s default dependencies.
If this guide helped you, share it with others facing the same issue! 🚀