Chl*_*loe 19 java spring maven build-dependencies spring-boot
当我跑步时,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
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml.对JSON的唯一引用是
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Apache Maven 3.5.3
use*_*900 32
添加下
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
Run Code Online (Sandbox Code Playgroud)
以下排除:
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
Run Code Online (Sandbox Code Playgroud)
Pla*_*nky 15
背景:
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
添加gradle依赖:
implementation('com.github.openjson:openjson:1.0.12')
Run Code Online (Sandbox Code Playgroud)
或者在 Maven 中:
implementation('com.github.openjson:openjson:1.0.12')
Run Code Online (Sandbox Code Playgroud)
然后更新org.json类正在使用的任何导入。
为gradle项目添加以下行。
testCompile('org.springframework.boot:spring-boot-starter-test'){
exclude group: "com.vaadin.external.google", module:"android-json"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5446 次 |
| 最近记录: |