将数据存储Cassandra驱动程序升级到3.0.1后,我的JUnit测试用例中断了。 添加了一项检查,以确保按照Datastax升级页面point 3中所述使用Google guava版本16.0.1。
我明确地在google guava上添加了依赖,最新版本为19.0 ,但这似乎没有帮助,因为测试用例仍然会抛出番石榴版本异常。
为了澄清,只有在执行单元测试时才编译代码。在pom.xml中明确添加19.0时,我无法理解为什么在类路径中旧版本的guava被拾取?我做错了什么?
其他一些帖子如this one描述了Spark和Hadoop的解决方案,但这是一个WAR项目,所以我在maven中运行了一个依赖树,看到19.0取代了推荐的16.0.1。
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:3.0.1:compile
...
[INFO] | +- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 19.0)
详细信息从此处开始
异常堆栈跟踪:
java.lang.ExceptionInInitializerError
at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1274)
at org.cassandraunit.spring.AbstractCassandraUnitTestExecutionListener.startServer(AbstractCassandraUnitTestExecutionListener.java:61)
at org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener.prepareTestInstance(CassandraUnitDependencyInjectionTestExecutionListener.java:21)
at ...
Caused by: java.lang.IllegalStateException: Detected Guava issue #1635 which indicates that a version of Guava less than 16.01 is in use. This introduces codec resolution issues and potentially other incompatibility issues in the driver. Please upgrade to Guava 16.01 or later.
at com.datastax.driver.core.SanityChecks.checkGuava(SanityChecks.java:62)
at com.datastax.driver.core.SanityChecks.check(SanityChecks.java:36)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:68)
... 25 more
如果有兴趣,请check out the source code查看支票的内容。
Pom.xml相关部分是:
<!-- Spring data cassandra -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>${org.springframework.data.cassandra.version}</version>
</dependency>
<!-- Cassandra in memory unit testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>2.1.3.2-SNAPSHOT</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-shaded</artifactId>
<version>2.1.3.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hectorclient</groupId>
<artifactId>hector-core</artifactId>
<version>2.0-0</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<!-- Datastax Cassandra Java driver -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.1</version>
</dependency>
这是来自maven的依赖树。复制相关部分只是因为它太大了。
...
[INFO] +- com.google.api-client:google-api-client:jar:1.20.0:compile
[INFO] | +- com.google.oauth-client:google-oauth-client:jar:1.20.0:compile
[INFO] | | +- com.google.http-client:google-http-client:jar:1.20.0:compile
[INFO] | | | +- (com.google.code.findbugs:jsr305:jar:1.3.9:compile - omitted for duplicate)
[INFO] | | | \- (org.apache.httpcomponents:httpclient:jar:4.0.1:compile - omitted for conflict with 4.3)
[INFO] | | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | +- com.google.http-client:google-http-client-jackson2:jar:1.20.0:compile
[INFO] | | +- (com.google.http-client:google-http-client:jar:1.20.0:compile - omitted for duplicate)
[INFO] | | \- (com.fasterxml.jackson.core:jackson-core:jar:2.1.3:compile - omitted for conflict with 2.3.0)
[INFO] | \- com.google.guava:guava-jdk5:jar:13.0:compile
...
[INFO] +- org.springframework.data:spring-data-cassandra:jar:1.3.2.RELEASE:compile
[INFO] | +- org.springframework.data:spring-cql:jar:1.3.2.RELEASE:compile
[INFO] | | +- (org.springframework:spring-context:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.springframework:spring-beans:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.springframework:spring-core:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.springframework:spring-expression:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- org.springframework:spring-tx:jar:4.1.9.RELEASE:compile
[INFO] | | | +- (org.springframework:spring-beans:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | | \- (org.springframework:spring-core:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.springframework.data:spring-data-commons:jar:1.11.2.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (com.datastax.cassandra:cassandra-driver-dse:jar:2.1.5:compile - omitted for duplicate)
[INFO] | | +- (com.google.guava:guava:jar:14.0:compile - omitted for conflict with 19.0)
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - omitted for conflict with 1.7.5)
[INFO] | | \- (org.slf4j:jcl-over-slf4j:jar:1.7.13:runtime - omitted for conflict with 1.7.5)
[INFO] | +- (org.springframework:spring-expression:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.11.2.RELEASE:compile
[INFO] | | +- (org.springframework:spring-core:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.springframework:spring-beans:jar:4.1.9.RELEASE:compile - omitted for conflict with 4.1.6.RELEASE)
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - omitted for conflict with 1.7.5)
[INFO] | | \- (org.slf4j:jcl-over-slf4j:jar:1.7.13:runtime - omitted for conflict with 1.7.5)
[INFO] | +- com.datastax.cassandra:cassandra-driver-dse:jar:2.1.5:compile
[INFO] | | \- (com.datastax.cassandra:cassandra-driver-core:jar:2.1.5:compile - omitted for conflict with 3.0.1)
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - omitted for conflict with 1.7.5)
[INFO] | \- (org.slf4j:jcl-over-slf4j:jar:1.7.13:runtime - omitted for conflict with 1.7.5)
...
[INFO] +- org.hectorclient:hector-core:jar:2.0-0:test
[INFO] | +- (commons-lang:commons-lang:jar:2.4:test - omitted for duplicate)
[INFO] | +- commons-pool:commons-pool:jar:1.5.3:test
[INFO] | +- org.apache.cassandra:cassandra-thrift:jar:2.0.4:test
[INFO] | | +- (org.apache.commons:commons-lang3:jar:3.1:test - omitted for duplicate)
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.2:test - omitted for conflict with 1.7.12)
[INFO] | | \- (org.apache.thrift:libthrift:jar:0.9.1:test - omitted for conflict with 0.9.2)
[INFO] | +- (com.google.guava:guava:jar:14.0:compile - scope updated from test; omitted for duplicate)
[INFO] | +- (org.slf4j:slf4j-api:jar:1.6.1:test - omitted for conflict with 1.7.12)
[INFO] | +- com.github.stephenc.eaio-uuid:uuid:jar:3.2.0:test
[INFO] | +- com.ecyrd.speed4j:speed4j:jar:0.9:test
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.6.1:test - omitted for conflict with 1.7.12)
[INFO] | \- com.yammer.metrics:metrics-core:jar:2.2.0:test
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.2:test - omitted for conflict with 1.7.12)
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:3.0.1:compile
[INFO] | +- io.netty:netty-handler:jar:4.0.33.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.0.33.Final:compile
[INFO] | | | \- io.netty:netty-common:jar:4.0.33.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.0.33.Final:compile
[INFO] | | | \- (io.netty:netty-buffer:jar:4.0.33.Final:compile - omitted for duplicate)
[INFO] | | \- io.netty:netty-codec:jar:4.0.33.Final:compile
[INFO] | | \- (io.netty:netty-transport:jar:4.0.33.Final:compile - omitted for duplicate)
[INFO] | +- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 19.0)
[INFO] | \- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.12)
答案 0 :(得分:1)
正如你自己指出的那样,罪魁祸首确实是google-api-client
,它取决于一个名为guava-jdk5
的非标准番石榴罐,它将Guava 13.0带到你的类路径。
尝试排除它:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.20.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>