当我运行mvn test
时,我会收到这样的警告。我怎么才能修好它?
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
这是我的pom.xml。对JSON的唯一引用是
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
Apache 3.5.3
发布于 2018-10-25 02:35:21
加在下面
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
下列排除:
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
同样,对于分级项目:
testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module:"android-json"
}
发布于 2020-03-31 14:22:45
背景:org.json
工作得很好,但是有一个一些人不喜欢的许可条款(“软件应该用于善,而不是邪恶。”)所以Vaadin想要使用这个图书馆,但是不能确定将来他们不会用它来作恶。相反,他们重新实现了接口,发布了android-json
,并将其作为org.json
的替代物。其他人也开始使用android-json
,这样他们也不会被不使用他们的软件作恶的要求所束缚。
这是一个很好的解决方案,只不过当两个库位于类路径上时,它们就会发生碰撞。
解决方案:--如果您从冲突的传递依赖中获得此错误,那么最好的选择是排除Vaadin的android-json
库(由Spring引入),或者排除org.json
库(由另一个依赖项引入)。Vaadin的版本意味着是一个相同的实现,但有细微的差别。
如果您在代码中使用org.json
,并且它与Spring的Vaadin依赖关系相冲突,那么我建议尝试使用open-json
。这是Vaadin重新实现org.json
的一个端口,但是他们更改了包,这样您就不会与org.json:json
或com.vaadin.external.google:android-json
有任何冲突。
https://github.com/openjson/openjson
添加分级依赖关系:
implementation('com.github.openjson:openjson:1.0.12')
或者在Maven:
<dependency>
<groupId>com.github.openjson</groupId>
<artifactId>openjson</artifactId>
<version>1.0.12</version>
</dependency>
然后更新org.json
类使用的任何导入。
发布于 2018-11-05 06:59:15
为gradle项目添加下面一行。
testCompile('org.springframework.boot:spring-boot-starter-test'){
exclude group: "com.vaadin.external.google", module:"android-json"
}
https://stackoverflow.com/questions/52980064
复制相似问题