Search code examples
scalamavenintellij-ideascalatest

Unit tests working well with maven but won't run when using them with IntelliJ


I have some unit tests in a Scala project that are working fine when using mvn clean test to run them (scalatest-maven-plugin version 1.0).

However, when I try to use IntelliJ UI to run them I get this error:

objc[56331]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f8774c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1102d24e0). One of the two will be used. Which one is undefined.
java.lang.IllegalArgumentException: ERROR: -r has been deprecated for a very long time and is no longer supported, to prepare for reusing it for a different purpose in the near future. Please change all uses of -r to -C.
    at org.scalatest.tools.ArgsParser$.checkArgsForValidity(ArgsParser.scala:41)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:857)
    at org.scalatest.tools.Runner$.run(Runner.scala:850)
    at org.scalatest.tools.Runner.run(Runner.scala)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)

Probably it has something to do with a dependency that I have in the pom. It is a dependency to an artifact that I have developed in a separated project. If I remove that dependency, this error disappears.

I need that dependency and I cannot figure out what is wrong with it. Maven is working just fine but I would like to have access to the debugger in IntelliJ.

Any suggestions? I have run out of ideas now and Google is not giving me anything useful so far.

Also, other colleagues are experiencing the same, so I doubt it has something to do with my local configuration.

Thanks in advance!


Solution

  • The "scalatest" library does not like the way that IntelliJ is invoking it.

    Try updating your Scala plugin in IntelliJ?

    UPDATE:

    I have done some digging in the source code of IntelliJ and Scalatest (both can be seen in the stack trace you showed above):

    1) Scalatest rejects this "-r" arg that IntelliJ is passing it here:

    https://github.com/scalatest/scalatest/blob/b97f944f4a2690744c26dc875097407baba7e21d/scalatest/src/main/scala/org/scalatest/tools/ArgsParser.scala#L41

    2) The IntelliJ code which passes arg "-r" is here:

    https://github.com/JetBrains/intellij-scala/blob/88317c1dd8a8cd6b8578adc17c1ead36a2a5a77a/scala/runners/src/org/jetbrains/plugins/scala/testingSupport/scalaTest/ScalaTestRunner.java#L131

    Notice that this is not the latest version of the IntelliJ scala plugin.

    Interestingly, the "-r" arg is only passed if this code has set isOlderScalaTestVersion true (see line 94), which appears to be if the detected ScalaTest version is 1.x (see line 261)

    So my current guess (without the benefit of a repro case) is that something about your linked library is causing IntelliJ Scala plugin to think that you are using ScalaTest 1.x, but actually you are using ScalaTest 3.x? Does the linked library have a transitive dependency on an old ScalaTest?