我使用Buildr 1.4.20(在64位Linux上使用Ruby 2.0.0)并尝试将ScalaTest与Scala 2.11.2一起使用,但我得到以下ClassNotFoundException
每次我尝试运行buildr test
。
Running tests in MyProject
ScalaTest "MySimpleTest"
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoClassDefFoundError: scala/xml/MetaData
at org.scalatest.tools.ReporterFactory.createJunitXmlReporter(ReporterFactory.scala:209)
at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:230)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:242)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:241)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:43)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:43)
at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:241)
at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:245)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2720)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
at org.scalatest.tools.Runner$.run(Runner.scala:883)
at org.scalatest.tools.ScalaTestAntTask.execute(ScalaTestAntTask.scala:329)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
Caused by: java.lang.ClassNotFoundException: scala.xml.MetaData
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1365)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 19 more
当然,我认为我可以通过在其中添加scala.xml.MetaData
依赖项来解决此问题,因此我添加了" org.scala-lang.modules:scala-xml_2.11:jar: 1.0.2" 到我的测试类路径,但我仍然得到相同的错误。
我确定该类确实存在于.jar文件中:
atg@host:~> zipinfo ~/.m2/repository/org/scala-lang/modules/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar | grep MetaData
-rw---- 2.0 fat 1441 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$asAttrMap$1.class
-rw---- 2.0 fat 1312 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$toString$1.class
-rw---- 2.0 fat 1215 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$toString1$1.class
-rw---- 2.0 fat 4197 bl defN 14-May-20 10:09 scala/xml/MetaData$.class
-rw---- 2.0 fat 10489 bl defN 14-May-20 10:09 scala/xml/MetaData.class
...所以我只能假设test.with
不是在Scala项目中添加此依赖项的正确方法。任何人都可以就如何解决这个问题提出任何建议吗?
我的整个构建文件如下:
# enable Scala 2.11.2
Buildr.settings.build['scala.version'] = "2.11.2"
Buildr.settings.build['scala.test'] = 'org.scalatest:scalatest_2.11:jar:2.2.2'
Buildr.settings.build['scala.check'] = 'org.scalacheck:scalacheck_2.11:jar:1.11.6'
require 'buildr/scala'
VERSION_NUMBER = "1.0-SNAPSHOT"
GROUP = "..."
COPYRIGHT = "..."
repositories.remote << "http://repo1.maven.org/maven2"
DEPS_COMPILE = "javax.servlet:javax.servlet-api:jar:3.1.0"
desc "..."
define "MyProject" do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with DEPS_COMPILE
test.with "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2"
end
答案 0 :(得分:0)
你的构建文件没问题,这似乎是buildr的一个问题。
作为一种解决方法,您可以在ant依赖项中添加scala-xml,如下所示:
VERSION_NUMBER = "1.0-SNAPSHOT"
GROUP = "..."
COPYRIGHT = "..."
Ant.dependencies << "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2"
您还应该在buildr的存储库中发出错误。