Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Intellij breakpoints ignored

I am doing the Scala introductory course from Coursera.

Within Intellij, I am trying to debug but breakpoints are ignored.

Unlike in this question: Can't debug a Scala application in IntelliJ + sbt-idea-plugin, I am not getting any error.

Do I need to install something or set some Intellij configurations?

like image 970
octavian Avatar asked Nov 29 '15 21:11

octavian


1 Answers

Someone recently walked me through debugging in InteliJ using scala/scalatest. I am running InteliJ Idea 2017.2 with the latest scala language plugin installed, no SBT plugin installed (as far as I can tell this is just part of the scala plugin now). Hopefully this helps some other people out:

  1. Set breakpoints by clicking next to the line number you want to test.
  2. Assuming you are using ScalaTest to set up some conditions and run your program, you can right-click on one of your test classes, and then select Debug '[classname]' from the dropdown. This should pop open the debug pane on the bottom. enter image description here

When you use InteliJ to run the debugging directly (not attaching through sbt etc) I was actually able to get this to work. I have not had success with any of the answers to related questions that discuss attaching to a running sbt process (with scalatest at least).

There are a lot of useful things that intelij debug gives you with scalatest at this point. Say there is one test that is failing and you want to dig into why. On the debug window, click the console tab, and you will see a list of your tests ordered by suite w/ red marks next to the ones that failed. You can right-click on a single test and select debug from the dropdown to only debug that one test. It's pretty useful. enter image description here

Hopefully that helps some other people! I also hit a few gotchas I should outline:

  1. Sometimes I need to re-load the sbt project (click the circular arrow thing under the sbt project tab on the left). It takes a while but it cleans up some random errors about classes not being found, and even unrelated sounding things like One or more requested classes are not Suites. enter image description here
  2. I sometimes get errors about shaded classes not found, especially when using docker through sbt (for example to spin up a db node in my tests). To get around that I first deleted the cached compiled jar (rm -r $HOME/.ivy2/cache/com.spotify/ for example to get rid of the cached compiled code that was causing problems) then I reloaded the project as in step-1.
  3. If all else fails, make sure that the project is properly imported. You might need to delete the .idea folder in your folder and re-import the sbt project. This trashes your settings and all, but it's worked for me as a last resort in the past.
like image 166
John St. John Avatar answered Oct 22 '22 12:10

John St. John