Search code examples
scalamavenscalatest

scalatest - can't expand macros compiled by previous versions of Scala


So we have a Scala program (built using Maven) we want to test using Scalatest. We're running Scala 2.11.8 and Scalatest 3.0.1 (we've tried 3.0.3 to no avail)

When our tests run anything with the assert() macro, we get the following error:

error: can't expand macros compiled by previous versions of Scala
       assert(true)
              ^

It points to the true but the issue is with anything we put into assert(). Our POM has the following dependency for Scalatest:

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

The code we're trying to execute is:

import org.scalatest.{FlatSpec, _}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner


@RunWith(classOf[JUnitRunner])
class Testing extends FlatSpec {
  //test
  var number = 0;
  "An empty Set" should "have size 0" in {
    assert(true)

  }
}

Lot's of folks say this is an issue with using Scala 2.11 but including the 2.10 dependency, but we're using the 2.11 one. Any help would be much appreciated. I should also note we tried it using Scala 2.10, and it worked.


Solution

  • Run mvn dependency:tree and find out which dependencies have _2.10 in it. Use Dependency management to ensure the _2.11 is included, and _2.10 is excluded.