Debugging a webapp launched from IntelliJ does not stop at breakpoints

I have been unable to use a GradelScriptRunner using the tooling api and the IntelliJ debugger. I can use breakpoints in the GradelScriptRunner but no breakpoints inside the main application are recognized. Is this because of the way the tooling API launches the jettyRun task in a daemon process which prevents Intellij attach to to process (im guessing here how this works)? I double checked that the compiled code contains debug metadata, any suggestions?

class GradleScriptRunner {
    public static void main(String[] args) {
        ProjectConnection connection = GradleConnector.newConnector()
            .forProjectDirectory(new File("."))
            .connect()
          try {
            connection.newBuild()
                    .forTasks("jettyRun")
                    .withArguments("-b", "webapp.gradle")
                    .setJvmArguments("-Xmx1024m", "-XX:MaxPermSize=256m", "-Dtapestry.execution-mode=DevelopmentMode")
                    .run()
        } finally {
            connection.close();
        }
    }
}

The Gradle build will run in a different process (namely a Gradle daemon process) than ‘GradleScriptRunner’, so you’ll have to connect to that process. You’ll also have to set the usual JVM arguments (’-Xdebug’ etc.) to allow a debugger to be attached.

I had found that solution myself. I updated my GradleScriptRunner to include the debug commands:

class GradleScriptRunner {
    public static void main(String[] args) {
        ProjectConnection connection = GradleConnector.newConnector()
            .forProjectDirectory(new File("."))
            .connect()
        try {
            connection.newBuild()
                    .forTasks("jettyRun")
                    .setJvmArguments("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007")
                    .run()
        } finally {
            connection.close();
        }
    }
}

which I then launched by using a normal Application configuration in Intellij. I then created a second Remote configuration to attach to the Gadle build process and I was able to work/debug fine. At least it works now, thanks.