If you use Gradle to run your tests, and are an Eclipse user but the project you are working in is not an Eclipse project, you might think that you are out of luck when it comes to debugging. But that’s not the case, you can use Eclipse to debug a test you can launch with Gradle.
Step #1: launch the test in Gradle
Launch your test with Gradle. Supposing your test is x.y.MyTest, run Gradle as follows:
gradle test --debug-jvm --tests x.y.MyTest
Because you are using the –debug-jvm thing, Gradle will wait for a debugger to get attached, as shown below:
STEP #2: create a Java launcher for remote debugging
To atttach the Eclipse debugger, open Eclipse and go to Run|Debug Configurations…, and create a new launcher: select the Remote Java Application type. The key point here is to use the same port Gradle is using, in this case 5005. I have called this debug launcher Gradle, debug, and have configured it as follows:
Step #3: tell the launcher where to find the source code
To tell Eclipse where to find the source code, go to the Source tab in the launcher configuration. Click Add…, and choose the directory for your Java source code.
Now you can use Eclipse to place some breakpoints, step through your code, etc. Just open the launcher and click Debug. Voilá!
I have tested this with Gradle 2.3 and Eclipse Luna (4.4.2).