I have a project with compile dependencies on Swagger which brings jackson-databind v2.4.5 and a testCompile dependency on a library that makes use of AWS SDK which brings jackson-databind v2.6.6.
When running a test from gradle, everything works fine and the correct updated jackson dependency v2.6.6 is on classpath:
+--- io.swagger:swagger-jersey2-jaxrs:1.5.10
| +--- io.swagger:swagger-jaxrs:1.5.10
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.4.5
| | | +--- com.fasterxml.jackson.core:jackson-core:2.4.5 -> 2.6.6
| | | \--- org.yaml:snakeyaml:1.12 -> 1.13
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.4.5
| | | +--- com.fasterxml.jackson.core:jackson-core:2.4.5 -> 2.6.6
| | | +--- com.fasterxml.jackson.core:jackson-databind:2.4.5 -> 2.6.6
The intellij dependencies contain both versions:
However when running tests from IntelliJ, IntelliJ creates a "classpath jar" ( because the classpath is too long). When inspecting the classpath in the META-INF/MANIFEST.MF, I can see that only the smaller version jar (2.4.5) is included.
This causes an exception when the tests use the AWS SDK:
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.enable([Lcom/fasterxml/jackson/core/JsonParser$Feature;)Lcom/fasterxml/jackson/databind/ObjectMapper;
Because the older jackson API did not contain this method.
Is this somehow preventable? I am currently using a workaround where I added the version 2.6.6 of the jackson-databind dependency in the testCompile dependencies. But I would like to avoid this, because
Note that we use IntelliJ test runner simply because it's faster than running tests through gradle on local workstations (mainly due to incremental compilation).
答案 0 :(得分:0)
不能说,为什么IDE仍然有这个库的2个版本,尽管Gradle解决了依赖关系。您可以尝试手动排除对jackson-databind v2.4.5的传递依赖,如下所示:
compile('io.swagger:swagger-jersey2-jaxrs:1.5.10') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
然后同步Gradle和IDEA项目。