Problem debugging build with eclipse remote debugger

I am trying to debug a gradle build. In cmd I type:

set GRADLE_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

next I build the project:

gradle build

But instead of waiting for me to launch the remote debugging inside eclipse the build terminates:

C:\workspac\test>gradle build
  Listening for transport dt_socket at address: 8000
  INFO: Added configuration: provided
  ...
  ...
  BUILD SUCCESSFUL
    Total time: 9.881 secs

Why does the gradle build not wait for me to connect with the remote debug process from eclipse?

Because you set ‘suspend=n’.

Ah yes changing to suspend=y makes it wait, thanks!

I then set a breakpoint in my build.gradle file in a task that I am running from commandline. But it never stops at the breakpoint when I launch the remote debug process from eclipse (socket Attach on port 5005).

Do I need to run the build with some special parameter?

Without special tooling support, you won’t be able to step through build scripts in the debugger. And from what I know, the Eclipse Gradle tooling doesn’t currently provide such support. You should be able to debug custom task classes and plugin classes though, as long as you make them known to the IDE.

Ok I can now debug a plugin I have written and applied in my script. In my script I also call a java class:

afterEvaluate{
        project.javaexec {
          main = com.MyMain
          ...

Even though I set a breakpoint in MyMain it does not stop in the class. Is this expected behavior too?

‘project.javaexec’ creates a new process, so you’ll have to debug that process (and set the usual debug JVM args for it). To simplify this, you can do ‘javaexec { debug = true }’. For more information, see the DSL reference for ‘JavaExec’.

Thanks I can now debug my executed java code :slight_smile:

Should I be able to set breakpoints in an inline groovy method that’s embedded in my gradle script?

eg:

task info << {
 logger.lifecycle('info')
 sendNotification(new URL(jobUrl), 'RUNNING')
...
  void sendNotification(URL jobUrl, String status) {
 logger.lifecycle("sendNotification: ${jobUrl} = ${status}") <- break here?
 try {
  HttpURLConnection httpCon = (HttpURLConnection) jobUrl.openConnection()
  httpCon.setDoOutput(true)
  httpCon.setRequestMethod("PUT")
...

I am doing something wrong as that’s not working. The debugger connects and runs to completion without breaking.