I have the following scenario:
Machine A: Executing a JUnit test using Gradle:
./gradlew :<directory> --tests <ClassName> --info
Machine B: I have an IDE (like IntelliJ). I want to create a remote Java debug configuration to machine A and debug the test.
I came across “–debug-jvm” option for gradlew for remote debug. Using this parameter, the Gradle test runner is getting suspended on port 5005 by default. I can connect to this process only from the same machine (machine A) but not from machine B.
I followed the steps mentioned at Debugging with Gradle – dead fish But even with this configuration, I am unable to debug from machine B. I always get “Connection refused” error from the IDE in machine B.
With Gradle’s --info option, I can see the following parameters added to JVM started for running the tests:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
For remote debugging I believe address should have “*:” before the port number. For example:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005
But the “–debug-jvm” is not adding “*:” to the parameters.
Also tried the following things:
- Adding “debugOptions” to the Gradle’s “test” task: debugOptions { enabled = true port = 8166 server = true suspend = true } The result is the same. Not able to connect from machine B and results in “Connection refused” error in IDE.
- Adding following properties to gradle.proprties:
org.gradle.daemon=false
org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:10999
Gradle’s daemon thread is suspended with the above properties but not the test executor thread.
Gradle version: 5.6.2
Java version: JDK 11
Things are working if everything (running the tests and IDE) is on a single machine.
So the question is, how to really “remote” debug a JUnit test that is executed using Gradle?
Thanks for your help!