Setting up gradle debug configuration for all projects
$ touch ~/.gradle/init.gradle
$ cat > ~/.gradle/init.gradle <<EOF
allprojects {
tasks.withType(Test) {
if (System.getProperty('DEBUG', 'false') == 'true') {
jvmArgs '-Xdebug',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009'
}
}
tasks.withType(JavaExec) {
if (System.getProperty('DEBUG', 'false') == 'true') {
jvmArgs '-Xdebug',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009'
}
}
}
EOF
Import the gradle project in Eclipse as usual
Setup Remote Java Application
Open Eclipse and go to Run -> Debug Configurations.... Select the Remote Java Application in the list of configuration types on the left. Click the New toolbar button. In the Project field of the Connect tab, type or browse to select the project to use as a reference for the launch (for source lookup). In the Host field of the Connect tab, type the IP address or domain name of the host where the Java program is running. If the program is running on the same machine as the workbench, type localhost. In the Port field of the Connect tab, type the port where the remote VM is accepting connections. In our case the port will be 9009. Click Apply and then Debug.
Enable gradle Debug
For test task debugging run $ gradle -DDEBUG=true test in the terminal. For run task debugging run $ gradle -DDEBUG=true run in the terminal. Now you can use your Eclipse debugger to debug