Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on scalatest compilation in IDEA

I am trying to compile Scala project which contains scalatest. It compiles normal on sbt

sbt
> compile
> test:compile

, but when I am trying to build it with IDEA, it shows the following error:

Error:(37, 11) exception during macro expansion: 
java.lang.NoSuchMethodError: org.scalactic.BooleanMacro.genMacro(Lscala/reflect/api/Exprs$Expr;Ljava/lang/String;Lscala/reflect/api/Exprs$Expr;)Lscala/reflect/api/Exprs$Expr;
at org.scalatest.AssertionsMacro$.assert(AssertionsMacro.scala:34)
assert((ElementMeasures.baseElementDistance(mEl1, mEl2) - 0.33333).abs < 0.001)
      ^

for each assert function in test.

build.sbt file contains following:

name := "ner-scala"
organization := "ml.generall"
version := "1.0-SNAPSHOT"
scalaVersion := "2.11.8"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
...
like image 939
generall Avatar asked Oct 01 '16 22:10

generall


People also ask

How do I run ScalaTest in IntelliJ?

Open the test in the editor, press Ctrl+Shift+F10 or right-click on the test class and from the context menu select Run 'test name'. IntelliJ IDEA creates a run/debug configuration for the test automatically, but if you want to edit settings in your configuration, click Run | Edit Configurations on the main menu.

How do I add Scala framework support in IntelliJ?

To add Scala support to existing module:Right-click the module in Project View, choose “Add Framework Support…” Check “Scala” in technologies list (unavailable if module has Scala facet attached) Provide a path to Scala installation (if not detected)


2 Answers

It may also mean that you have more than one versions of scalatest registered. I came into pretty same issue with compile-time error on assert

like image 199
Alexey Avatar answered Sep 30 '22 18:09

Alexey


I just ran into the same problem and as Alexey described (he should get the upvote but I don't have enough reputation to upvote or comment - thank you Alexey), it seems that it was caused by having multiple versions of scalatest in my project. I was able to fix it by specifically excluding the older scalatest from the library that brought it in (and please note that the exclude needs to specify the scala binary version, e.g. _2.11 etc.!):

...exclude("org.scalatest", "scalatest_2.11")

There had also been a warning in the event log before the exclude:

SBT project import
[warn] Multiple dependencies with the same organization/name but different versions.
[warn]  * org.scalatest:scalatest_2.11:(2.2.6, 3.0.1)
like image 28
medale Avatar answered Sep 30 '22 20:09

medale