Can't run Scalatest with Gradle

Joshua MN picture Joshua MN · Sep 16, 2013 · Viewed 14.7k times · Source
task scalaTest(dependsOn: testClasses) << {
    description = 'Runs Scalatest suite'
    ant.taskdef(name: 'scalatest',
            classname: 'org.scalatest.tools.ScalaTestAntTask',
            classpath: sourceSets.test.runtimeClasspath.asPath
    )
    ant.scalatest(runpath: sourceSets.test.output.classesDir,
            haltonfailure: 'true', fork: 'false') {
        reporter(type: 'stdout')
    }
}

I run gradle scalaTest and I get:

* What went wrong:
Execution failed for task ':scalaTest'.
> java.lang.NoClassDefFoundError: scala/reflect/ClassManifest$

I am using Scala 2.10.2 and Gradle 1.7

dependencies {
    compile 'org.scala-lang:scala-library:2.10.2'   
    testCompile 'org.scalatest:scalatest:1.3'
    testCompile 'org.scalamock:scalamock_2.10:3.0.1'
}

What's wrong??

Answer

rarry picture rarry · Sep 16, 2013

I do not know how to solve this one, but I can offer you a workaround. Annotate your test classes with @RunWith(classOf[JUnitRunner]), like this:

import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith

@RunWith(classOf[JUnitRunner])
class MyTest extends FunSpec{
}

and then, gradle test should work.

Edit:

My dependencies:

compile "org.scala-lang:scala-library:2.10.1"
testCompile "org.scalatest:scalatest_2.10:1.9.1"