[컴] log4j 가 충돌하는 이슈, gradle 설정

spring boot / issue

log4j 가 충돌하는 이슈, gradle 설정

아래 build.gradle 에서, log4j-slf4j-impllogback-classic 에서 모두 slf4j 를 사용해서 문제가 발생

from: SLF4J Multiple bindings were found on the class path

class path에 2개 이상의 binding이 있는 경우 SLF4J는 해당 binding 들의 위치들을 보여주고, warning을 내보낸다.

수정

위 글의 이야기 처럼 exclude를 이용해서 해결함.

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
plugins {
    id 'org.springframework.boot' version '2.4.5'
    id 'java'
    // ref: https://plugins.gradle.org/plugin/io.freefair.lombok
    id "io.freefair.lombok" version "8.0.1"
}
...
configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:2.6.6'
    implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.6'
    implementation 'org.springframework.boot:spring-boot-starter:2.6.6'

    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
    ...

    implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2'
    implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
    implementation 'org.apache.logging.log4j:log4j-api:2.17.2'

    runtimeOnly 'mysql:mysql-connector-java:8.0.28'

    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.6'

}

tasks.named('test', Test) {
    useJUnitPlatform()
}

binding error log

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
5 actionable tasks: 3 executed, 2 up-to-date

D:\myproj>gradlew bootRun

> Task :bootRun FAILED
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/myuser/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.2/log4j-slf4j-impl-2.17.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/myuser/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at com.me.MyRobotApplication.main(MyRobotApplication.java:10)  
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
        at org.apache.logging.slf4j.Log4jLoggerFactory.validateContext(Log4jLoggerFactory.java:60)  
        at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:44)        
        at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:33)        
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:53)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)        
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)    
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)    
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
        at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:174)
        ... 1 more

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'D:\a\appss\jdk-11.0.16.101-hotspot\bin\java.exe'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
5 actionable tasks: 1 executed, 4 up-to-date

gradlew dependencies

D:\myproj>gradlew dependencies   

> Task :dependencies

------------------------------------------------------------
Root project 'MyRobot' - MyRobot
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
\--- org.projectlombok:lombok:1.18.26

bootArchives - Configuration for Spring Boot archive artifacts. (n)
No dependencies

compileClasspath - Compile classpath for source set 'main'.
+--- org.projectlombok:lombok -> 1.18.26
+--- org.springframework.boot:spring-boot-starter-web:2.6.6
|    +--- org.springframework.boot:spring-boot-starter:2.6.6
|    |    ...
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.6
|    |    |    +--- ch.qos.logback:logback-classic:1.2.11***
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.2
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.35 -> 1.7.36
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.36
|    |    |         \--- org.slf4j:slf4j-api:1.7.36
|    |    ...
|    |    \--- org.yaml:snakeyaml:1.29
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2***
|    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.36
|    \--- org.apache.logging.log4j:log4j-api:2.17.2
+--- org.apache.logging.log4j:log4j-core:2.17.2
|    \--- org.apache.logging.log4j:log4j-api:2.17.2
+--- org.apache.logging.log4j:log4j-api:2.17.2
\--- org.projectlombok:lombok:1.18.26

compileOnly - Compile only dependencies for source set 'main'. (n)
\--- org.projectlombok:lombok (n)

default - Configuration for default artifacts. (n)
No dependencies

developmentOnly - Configuration for development-only dependencies such as Spring Boot's DevTools.   
No dependencies

implementation - Implementation only dependencies for source set 'main'. (n)
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2 (n)***
+--- org.apache.logging.log4j:log4j-core:2.17.2 (n)
\--- org.apache.logging.log4j:log4j-api:2.17.2 (n)

lombok
\--- org.projectlombok:lombok:1.18.26

mainSourceElements - List of source directories contained in the Main SourceSet. (n)
No dependencies

productionRuntimeClasspath
+--- org.springframework.boot:spring-boot-starter-web:2.6.6
|    +--- org.springframework.boot:spring-boot-starter:2.6.6
|    |    ...
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.6
|    |    |    +--- ch.qos.logback:logback-classic:1.2.11***
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.2
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.35 -> 1.7.36
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.36
|    |    |         \--- org.slf4j:slf4j-api:1.7.36
|    |    ...
|    |    \--- org.yaml:snakeyaml:1.29
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2***
|    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.36
|    +--- org.apache.logging.log4j:log4j-api:2.17.2
|    \--- org.apache.logging.log4j:log4j-core:2.17.2
|         \--- org.apache.logging.log4j:log4j-api:2.17.2
+--- org.apache.logging.log4j:log4j-core:2.17.2 (*)
+--- org.apache.logging.log4j:log4j-api:2.17.2
\--- mysql:mysql-connector-java:8.0.28
     \--- com.google.protobuf:protobuf-java:3.11.4

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.springframework.boot:spring-boot-starter-web:2.6.6
|    +--- org.springframework.boot:spring-boot-starter:2.6.6
|    |    ...
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.6
|    |    |    +--- ch.qos.logback:logback-classic:1.2.11***
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.2
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.35 -> 1.7.36
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.36
|    |    |         \--- org.slf4j:slf4j-api:1.7.36
|    |    ...
|    |    \--- org.yaml:snakeyaml:1.29
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2***
|    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.36
|    +--- org.apache.logging.log4j:log4j-api:2.17.2
|    \--- org.apache.logging.log4j:log4j-core:2.17.2
|         \--- org.apache.logging.log4j:log4j-api:2.17.2
+--- org.apache.logging.log4j:log4j-core:2.17.2 (*)
+--- org.apache.logging.log4j:log4j-api:2.17.2
\--- mysql:mysql-connector-java:8.0.28
     \--- com.google.protobuf:protobuf-java:3.11.4

runtimeElements - Elements of runtime for main. (n)
No dependencies

runtimeOnly - Runtime only dependencies for source set 'main'. (n)
\--- mysql:mysql-connector-java:8.0.28 (n)

testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.       
\--- org.projectlombok:lombok:1.18.26

testCompileClasspath - Compile classpath for source set 'test'.
+--- org.springframework.boot:spring-boot-starter-web:2.6.6
|    +--- org.springframework.boot:spring-boot-starter:2.6.6
|    |    ...
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.6
|    |    |    +--- ch.qos.logback:logback-classic:1.2.11***
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.2
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.35 -> 1.7.36
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.36
|    |    |         \--- org.slf4j:slf4j-api:1.7.36
|    |    ...
|    |    \--- org.yaml:snakeyaml:1.29
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2***
|    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.36
|    \--- org.apache.logging.log4j:log4j-api:2.17.2
...

testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies

testImplementation - Implementation only dependencies for source set 'test'. (n)
\--- org.springframework.boot:spring-boot-starter-test:2.6.6 (n)

testResultsElementsForTest - Directory containing binary results of running tests for the test Test 
Suite's test target. (n)
No dependencies

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.springframework.boot:spring-boot-starter-web:2.6.6
|    +--- org.springframework.boot:spring-boot-starter:2.6.6
|    |    ...
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.6
|    |    |    +--- ch.qos.logback:logback-classic:1.2.11***
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.36
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.2
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.35 -> 1.7.36
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.36
|    |    |         \--- org.slf4j:slf4j-api:1.7.36
|    |    ...
|    |    \--- org.yaml:snakeyaml:1.29
...
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.17.2***
|    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.36
|    +--- org.apache.logging.log4j:log4j-api:2.17.2
|    \--- org.apache.logging.log4j:log4j-core:2.17.2
|         \--- org.apache.logging.log4j:log4j-api:2.17.2
...

testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies

(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.

(n) - A dependency or dependency configuration that cannot be resolved.

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

댓글 없음:

댓글 쓰기