4

I'm using Buildr 1.4.20 (with Ruby 2.0.0 on 64-bit Linux) and trying to use ScalaTest with Scala 2.11.2, but I'm getting the following ClassNotFoundException every time I try to run 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

Naturally, I thought I could fix this by adding a dependency with scala.xml.MetaData in it, so I added "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2" to my test classpath, but I still get the same error.

I'm sure the class is indeed present in the .jar file:

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

... so I can only assume that test.with isn't the right way to add this dependency in a Scala project. Can anyone please offer any advice on how to fix this?

My entire buildfile is as follows:

# 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
ATG
  • 1,679
  • 14
  • 25

1 Answers1

0

Your buildfile is ok, this seems to be a problem with buildr.

As a workaround, you could add the scala-xml in the ant dependencies, like so:

VERSION_NUMBER = "1.0-SNAPSHOT"
GROUP = "..."
COPYRIGHT = "..."
Ant.dependencies << "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2"

You should also issue a bug in the buildr's repository.

Tiago Engel
  • 3,533
  • 1
  • 17
  • 22
  • Thanks for the answer - I'll have a go with this in due course and see whether it works or not. – ATG May 27 '15 at 10:47