I have a strange problem: Sometimes ScalaTests fail in IDEA. What I get is:
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$.run(Runner.scala:883)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:138)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Other people having the same problem should set an option "run worksheet in the compiler process", but I cannot find it in my IDEA. I do not have File -> Settings -> Scala where it is supposed to be.
What should I do?
EDIT: I investigated some more, and what is really strange is: It is a multimodule SBT build and in some projects the tests work. I created a new module, added a very simple test and this test runs. Only the tests in one module fail with this error.
EDIT2: This seems a bug in the bundled SBT compiler, see this link. I now cleaned my directory, deleted my .ivy2
folder and try to reimport everything and see if this changes anything.
I found the cause for this. It is really how the Scala plug-in of IDEA works. My project was based on Scala 2.11 before and I switched it to use 2.10 because I added submodules using Spark which is built for Scala 2.10, and somehow IDEA still picked Scala 2.11 dependencies for the tests, even though my whole project was now using 2.10.
I deleted my .ivy2
folder, cleaned my project with git clean -fdx
and re-imported everything into IDEA, but this time, I did not use the built-in SBT, but the one I installed on my computer instead. Now it seems to work.
So as a rule of thumb, when doing very fundamental changes, I will nuke .ivy2
and re-import everything from scratch in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With