Debugging Gradle Tasks With IDE's Remote Debugger
There are a couple of ways you can use to debug Gradle in IntelliJ IDEA, Eclipse, or any other IDE.
Create a Remote Debugger
Before we start, you will need to create a Debugger configuration. It should be a Remote configuration, and you can leave all the configuration settings as they are.
Debugging Gradle Build Script
Gradle Build script is nothing else than a program written in Groovy or Kotlin language, which means that it could be debugged as regular code.
To debug a Gradle script, execute the following command:
./gradlew anyTask -Dorg.gradle.debug=true --no-daemon
After running this command, Gradle will initiate the script but won't proceed until you start the debugger.
It will not proceed until you start the remote debugger you created earlier.
Debugging Tests Started as Gradle Test Task
This way of debugging is useful for example debugging jUnit tests which are started as a task test
.
Remote debugger should be configured as before, then run the command:
./gradlew test --debug-jvm
This command starts a Gradle task, but it halts at the test execution step and waits until the Debugger is started. After that, you can begin debugging your unit tests.
Happy coding!