Why log4j2 still using old version in maven pom

Viewed 324

I follow this example to upgrade log4j2 but in dependency tree there is still old version. Why ?

<properties>
    <log4j2.version>2.16.0</log4j2.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.5.2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-bom</artifactId>
            <version>2.16.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
</dependencies>

dependency:

[INFO] \- org.springframework.boot:spring-boot-starter-logging:jar:2.5.2:compile
[INFO]    +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO]    |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO]    |  \- org.slf4j:slf4j-api:jar:1.7.31:compile
[INFO]    +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.14.1:compile
[INFO]    |  \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
[INFO]    \- org.slf4j:jul-to-slf4j:jar:1.7.31:compile
1 Answers

You will need to include the log4j-bom first, and then the spring bom:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-bom</artifactId>
            <version>${log4j2.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
Related