scalascalatestscala-2.11scalatest-maven-plugin

Scalatest throws weird error on scala 2.11


I'm using maven 3.3 + scala 2.10 for a small project. The scalatest framework works perfectly well. However, when I switch to scala 2.11 and replace all dependencies to 2.11:

    <dependency>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest_2.11</artifactId>
        <version>2.2.6</version>
        <scope>test</scope>
    </dependency>

The first time I ran mvn test it threw this error:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- scalatest-maven-plugin:1.0:test (test) @ spookystuff-core ---
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoSuchMethodError: scala.runtime.ObjectRef.create(Ljava/lang/Object;)Lscala/runtime/ObjectRef;
    at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2347)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)
    at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
    at org.scalatest.tools.Runner$.main(Runner.scala:860)
    at org.scalatest.tools.Runner.main(Runner.scala)

Can someone explain what does it means, and how to fix it?


Solution

  • OK I found the problem. Doing a mvn dependency:tree shows that a library doesn't ship with scala 2.11, when compiling its dependency still resolves to 2.10.

    The solution is to exclude its dependency:

        <dependency>
            <groupId>com.github.mdr</groupId>
            <artifactId>ascii-graphs_2.10</artifactId>
            <version>0.0.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    The everything becomes normal.