Debugging Scala code with simple-build-tool (sbt) and IntelliJ

There’s a very convenient -jvm-debug flag in the official SBT packages for Mac, Linux & Windows. You can use the flag to specify the debug port:

sbt -jvm-debug 5005

Under the covers, this starts the JVM for SBT with the typical verbose debugging incantation:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

You now can run your code as normal, for example with the sbt run command.

Configuring IntelliJ to connect to the running code…

Now you connect IntelliJ to your running process using a Remote Debug configuration. Note that the upper 3 fields in this form, while scary, are just for you to copy text out of, rather than into (they’re giving the verbose debugging incantation specified above, which -jvm-debug already takes care of for you) – the only configuration you can change is in theSettings section halfway down:

Remote Debug configuration in IntelliJ

Leave a Comment