Programming/Java

[Java] junit5 test 진행 중 DuplicateJsonObjectContextCustomizer

bisi 2022. 11. 3. 19:28

현상

단위 테스트 실행시 아래와 같이 JSONObject 관련해서 중복되는 class path가 존재한다는 로그가 출력되었다.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2020-07-15 14:35:10.047  WARN 32292 --- [           main] ory$DuplicateJsonObjectContextCustomizer : 

Found multiple occurrences of org.json.JSONObject on the class path:

    jar:file:/C:/log/apache-maven-3.5.4/repository/org/json/json/20090211/json-20090211.jar!/org/json/JSONObject.class
    jar:file:/C:/log/apache-maven-3.5.4/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class

You may wish to exclude one of them to ensure predictable runtime behavior

해결 방법

자동으로 중복으로 잡힌 것을 없애주려면, pom.xml 파일의 spring-boot-starter-test 에서 아래 내용을 exclusion 해준다.

                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>