sbt test给出:java.lang.NoClassDefFoundError:scala / collection / GenTraversableOnce $ class"

时间:2016-10-16 22:06:01

标签: scala sbt

当我跑步' sbt test'我明白了: " [error](test:executeTests)java.lang.NoClassDefFoundError:scala / collection / GenTraversableOnce $ class"

我猜测我正在使用特定的Scala版本,而ScalaTest期望使用不同的Scala版本。不过为什么会发生这种情况,我不知道!我想我正在使用Scala 2.11,这也是ScalaTest应该期待的。

有趣的是我实际上并没有使用ScalaTest。我只使用JUnit测试。

可以找到项目on GitHub。 我正在使用这个sbt文件:

name := "ParticleCompilerSbt"    
version := "1.0"    
scalaVersion := "2.11.8"

libraryDependencies += "com.fifesoft" % "rsyntaxtextarea" % "2.5.8"    
libraryDependencies += "org.swinglabs" % "swingx" % "1.6.1"    
libraryDependencies += "jgraph" % "jgraph" % "5.13.0.0"    
libraryDependencies += "org.tinyjee.jgraphx" % "jgraphx" % "2.3.0.5"    
libraryDependencies += "org.jgrapht" % "jgrapht-core" % "0.9.1"    
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.0" % "test"    
libraryDependencies += "junit" % "junit" % "4.12" % "test"    
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"    
libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.11.8"    
libraryDependencies += "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.5"    
libraryDependencies += "org.scala-lang.modules" % "scala-swing_2.11" % "2.0.0-M2"    
libraryDependencies += "org.scala-lang.modules" % "scala-parser-combinators_2.11" % "1.0.4"    
libraryDependencies += "org.apache.commons" % "commons-math3" % "3.5"    
libraryDependencies += "com.google.guava" % "guava" % "18.0"
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.1.3"
unmanagedResourceDirectories in Compile += baseDirectory.value / "testResources"

' sbt test'给出以下stacktrace:

java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class
        at org.scalatest.ConfigMap.<init>(ConfigMap.scala:97)
        at org.scalatest.tools.Runner$.parsePropertiesArgsIntoMap(Runner.scala:2219)
        at org.scalatest.tools.Framework.runner(Framework.scala:1026)
        at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:547)
        at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:541)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.immutable.Map$Map2.foreach(Map.scala:130)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at sbt.Defaults$.createTestRunners(Defaults.scala:541)
        at sbt.Defaults$.allTestGroupsTask(Defaults.scala:561)
        at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:424)
        at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:424)
        at scala.Function9$$anonfun$tupled$1.apply(Function9.scala:35)
        at scala.Function9$$anonfun$tupled$1.apply(Function9.scala:34)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.scalatest.ConfigMap.<init>(ConfigMap.scala:97)
        at org.scalatest.tools.Runner$.parsePropertiesArgsIntoMap(Runner.scala:2219)
        at org.scalatest.tools.Framework.runner(Framework.scala:1026)
        at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:547)
        at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:541)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.immutable.Map$Map2.foreach(Map.scala:130)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at sbt.Defaults$.createTestRunners(Defaults.scala:541)
        at sbt.Defaults$.allTestGroupsTask(Defaults.scala:561)
        at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:424)
        at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:424)
        at scala.Function9$$anonfun$tupled$1.apply(Function9.scala:35)
        at scala.Function9$$anonfun$tupled$1.apply(Function9.scala:34)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

我已经坚持了一段时间,所以感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

这一行:

libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.1.3"

您依赖于scala 2.10加载依赖项。我尝试将其升级到最新版本(2.4.11),但似乎有一些重大更改删除了akka.util.Convert包。您可能需要找到他们移动功能的位置或自己编写实用程序功能。

对于scala依赖项,我建议使用%%代替%,sbt会自动为您附加正确的scala版本。即代替

libraryDependencies += "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.5"
你做了

libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.5"

编辑:我认为ByteStringBuilder中的akka.util.ByteString是替代品。