I'm working on a Grails app that has a suite of (Geb) functional tests. I used to be able to debug these tests from inside IntelliJ, but now whenever I try to run the tests in debug mode I get the following error
ERROR: transport error 202: connect failed: Connection refused
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
Since the introduction of the fork mode I'd been struggling with debugging until I discovered this simple trick. In your BuildConfig.groovy change the
grails.project.fork
to something like this:Notice the
jvmArgs
in therun
andtest
configurations. This is simple passed onto Java when the fork mode executes.Next you have to configure remote debugging hooking onto the port as defined in the previous step.
For your convenience you can configure an external tool to wait for the debug to come alive and then start the debug session. Basically it run an
nc
in a loop until a specified port is alive. In the simplest form it looks like this:You can configure this script as an external tool and make it run before the debug starts (add it to the 'before launch' box when configuring a new remote debug session)