2012-08-17 23 views
3

我有一个使用maven和sbt的Java 1.6 + Scala 2.9.2项目。该项目的开工抛出该异常在测试时,我加入了番石榴缓存类:IncompatibleClassChangeError当用sbt测试番石榴代码时

java.lang.IncompatibleClassChangeError: 
class com.google.common.cache.CacheBuilder$3 has interface 
com.google.common.base.Ticker as super class 

sbt clean compile作品完美,但sbt clean test抛出该异常。

番石榴的版本是13.0

模块提高异常有:

import com.google.common.cache.{CacheBuilder, Cache} 
... 
val cache: Cache[String, Integer] = CacheBuilder.newBuilder() 
    .maximumSize(5000).build() 

我SBT依赖是:

libraryDependencies ++= Seq(
    "org.scala-tools.testing" %% "scalacheck" % "1.9" % "test" changing(), 
    "org.specs2" %% "specs2" % "1.9" % "test" 
) 

而且Maven的依赖关系是:

<dependencies> 
    <dependency> 
     <groupId>org.apache.thrift</groupId> 
     <artifactId>libthrift</artifactId> 
     <version>0.8.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>13.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.6.6</version> 
    </dependency> 
    <dependency> 
     <groupId>redis.clients</groupId> 
     <artifactId>jedis</artifactId> 
     <version>2.0.0</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>com.googlecode.json-simple</groupId> 
     <artifactId>json-simple</artifactId> 
     <version>1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.zookeeper</groupId> 
     <artifactId>zookeeper</artifactId> 
     <version>3.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.scalatest</groupId> 
     <artifactId>scalatest_2.9.1</artifactId> 
     <version>1.8</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.9.0</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-all</artifactId> 
     <version>1.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.novocode</groupId> 
     <artifactId>junit-interface</artifactId> 
     <version>0.8</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

回答

1

Ticker在Guava 13之前从Interface变为抽象类。

事实上,这种情况在测试中发生,但没有编译是一个很好的指标。

我认为一个早期版本的番石榴结束了你的测试类路径,可能作为传递依赖。

你可以尝试使用sbt-inspectr探索测试类路径,并找出更多的,或者你可以尝试排除,这样的:

"org.scala-tools.testing" %% "scalacheck" % "1.9" % "test" changing(), excludeAll(
    ExclusionRule(organization = "com.google.guava") 
) 
+0

我忘了说'SBT run'抛出异常一样,所以它是导致它的另一个依赖项。 感谢您使用'ExclusionRule'和'excludeAll'。 sbt-inspectr没有按预期工作,但使用手动管理的依赖关系似乎可以解决问题。 – MrD 2012-08-21 10:00:34