To debug the gradle-tomcat-plugin in Intellij IDEA there are two run/debug configurations required. It has not worked out for me to establish an debug connection as the server has been run from the CLI. Despite of the fact the GRADLE_OPTS has been set correctly. Both configurations has to be run from the IDE itself!

The entire example is available on GitHub It has been tested with Gradle 2.11 and JDK 1.8.0_65 on OSX with IDEA 15.0.2.

Problem: Debugging fails

If your GRADLE_OPTS are set correctly and you run an gradle task like tomcatRunWar to run the container, you get the following outcome.

$ gradle tomcatRunWar
Listening for transport dt_socket at address: 5005
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.11/userguide/gradle_daemon.html.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:tomcatRunWar
Started Tomcat Server
The Server is running at http://localhost:8080/spring-mvc
> Building 80% > :tomcatRunWar

That seems ok, because the server started and the JVM is listening on port 5005 to connect.

Remote debug configuration

Now it’s time to connect to the running server process with your InteliJ IDEA by adding an Remote configuration and setting it to the address 5005. That should look like this:

debugConfig.png

After editing the configuration it’s time to hit the debug button that responds with:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'

But something seems not to be working. For example if you set an break point into an controller and trigger the GET request the debugger is NOT stopping! It seems the the connection between the debugger and the running java process is not established.

Solution: Run embedded tomcat config in your IDE

Start your embedded tomcat also from IntelliJ IDEA by a run/debug config. To do so, create a simple Gradle config with your task like tomcatRunWar and set the JVM options direct in the config.

runEmbeddedTomcatConfig.png

After that, simply startup both configurations respectively in your IDE.

  • Start your embedded-tomcat with Run embedded tomcat config by hitting run-button.

  • Connect to it with your debug config by hitting debug-button.

ConnectedDebuggerToEmbeddedTomcat.png