Some ScalaTests won't run from IDEA - NoSuchMethodError

I have a weird problem: Sometimes ScalaTests fail in IDEA. I get:

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 have to set the "run worksheet at compile time" option, but I can't find it in my IDEA program. I don't have a file -> Settings -> Scala where it should be.

What should I do?

EDIT: I've researched a few more and what's really weird: this is a multi-module SBT build and in some projects the tests work. I created a new module, added a very simple test and this test passes. Only tests in one module exit with this error.

EDIT2: This looks like a bug in the SBT compiler kit, see this link. Now I have cleared my directory, deleted the folder, .ivy2

and try reimport everything and see if that changes anything.

+3


source to share


3 answers


I found the reason for this. Scala IDEA plugin actually works. My project was based on Scala 2.11 before, and I switched to using 2.10 because I added submodules using Spark, which is built for Scala 2.10, and somehow IDEA still chose Scala 2.11 dependencies for tests, even though the whole my project was now using 2.10.

I deleted my folder .ivy2

, cleaned my project with git clean -fdx

and again imported everything into IDEA, but this time I did not use the built-in SBT, but the one I installed on my computer. It works now.



So, generally, with very fundamental changes, I'll nuke .ivy2

and re-import everything from scratch in the future.

+2


source


It might be because your application and SBT are running a different version of Scala. When you import an SBT project into IDEA, it creates two modules for you: com-example-yourapp and com-example-yourapp-build. IDEA adds all SBT libraries (including Scala) depending on the project. The problem is that IDEA adds the SBT version of Scala to the classpath for some reason, and hence your tests run against it.

To Fix:



  • Open the project dependencies * -build.
  • Double click on SBT library: sbt and plugins.
  • Remove lib jars (scala -library.jar etc.) from Scala library.

It should now work.

0


source


this is a version mismatch. check your installed scala version and pom dependency version.

0


source







All Articles