Search code examples
scaladockerintellij-ideasbtremote-debugging

Intellij CE 2018.2 + SBT in docker container: Remote debug breakpoints not working


I have a Spark application for which I have many implemented tests. I run this test in SBT shell inside a docker container. I need to debug the application by connecting from Intellij, and even though it connects to the running instance of SBT shell, breakpoints are completely ignored.

I set fork/test to false.

Also used this cmd to launch SBT shell inside the container:

  • export SBT_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -Xmx4G"

  • Followed by command: sbt.

It displays the message

Listening for transport dt_socket at address: 5005

SBT shell suspends until Intellij debugger connects to the specified port.

Now I go to Intellij Remote debugger and the debug console displays this message:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'

Finally, SBT resumes and starts downloading dependencies.

When I run:

test:testOnly fully.qualified.class.name

And submit breakpoints, test cases are executed but all breakpoints are ignored.

I don't know what else to try! Please help!


Solution

  • Besides setting test/fork to false, fork in general should also be set to false. This includes running, building, etc.

    Also, make sure that the suspend flag in SBT_OPTS is set to yes, so that it waits until Intellij Remote Debugger connects to it to execute tests.

    That's it, that's how I got breakpoints to work when running from docker.