Maven + Spring Boot: Found multiple occurrences of org.json.JSONObject on the class path:

百般思念 提交于 2020-01-12 04:07:34

问题


When I run mvn test I get this warning. How can I fix it?

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

        jar:file:/C:/Users/Chloe/.m2/repository/org/json/json/20140107/json-20140107.jar!/org/json/JSONObject.class
        jar:file:/C:/Users/Chloe/.m2/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

Here is my pom.xml. The only reference to JSON is

    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>

Apache Maven 3.5.3


回答1:


Add under

 <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>

The following exclusion:

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

Similarly, for Gradle projects:

testCompile("org.springframework.boot:spring-boot-starter-test") {
    exclude group: "com.vaadin.external.google", module:"android-json"
}



回答2:


Add the below line for gradle projects.

testCompile('org.springframework.boot:spring-boot-starter-test'){
        exclude group: "com.vaadin.external.google", module:"android-json"
}



回答3:


This worked for me:

configurations {
     testImplementation.exclude group: 'com.vaadin.external.google', module: 'android-json'
}


来源:https://stackoverflow.com/questions/52980064/maven-spring-boot-found-multiple-occurrences-of-org-json-jsonobject-on-the-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!