Environments:
Command line outputs:
$ export GRADLE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=address=5005"
$ ./gradlew myproj-web-java:tomcatRunWar
Listening for transport dt_socket at address: 5005
Starting a Gradle Daemon, 2 incompatible and 2 stopped Daemons could not be reused, use --status for details
Run/Debug Configurations:
Debugger Mode: Attach to remote JVM
Use module classpath: myproj-parent:myproj-web-java:main
Start debugging, and Intellij outputs:
Connected to the target VM, address: 'localhost:5005', transport: 'socket'
I added breakpoint in controller and visit the page via browser. The page rendered correctly, I can see the log outputted in console, but the break point doesn't hit.
If I pause program in Intellij, I can see the stack of main thread:
kevent0:-1, KQueueArrayWrapper (sun.nio.ch)
poll:198, KQueueArrayWrapper (sun.nio.ch)
doSelect:117, KQueueSelectorImpl (sun.nio.ch)
lockAndDoSelect:86, SelectorImpl (sun.nio.ch)
select:97, SelectorImpl (sun.nio.ch)
select:101, SelectorImpl (sun.nio.ch)
read:179, SocketConnection$SocketInputStream (org.gradle.internal.remote.internal.inet)
fill:139, Input (com.esotericsoftware.kryo.io)
require:159, Input (com.esotericsoftware.kryo.io)
readInt:308, Input (com.esotericsoftware.kryo.io)
readSmallInt:120, KryoBackedDecoder (org.gradle.internal.serialize.kryo)
read:139, DefaultSerializerRegistry$TaggedTypeSerializer (org.gradle.internal.serialize)
read:36, Serializers$StatefulSerializerAdapter$1 (org.gradle.internal.serialize)
receive:80, SocketConnection (org.gradle.internal.remote.internal.inet)
receive:75, DaemonClientConnection (org.gradle.launcher.daemon.client)
receive:35, DaemonClientConnection (org.gradle.launcher.daemon.client)
monitorBuild:211, DaemonClient (org.gradle.launcher.daemon.client)
executeBuild:179, DaemonClient (org.gradle.launcher.daemon.client)
execute:142, DaemonClient (org.gradle.launcher.daemon.client)
execute:93, DaemonClient (org.gradle.launcher.daemon.client)
run:52, RunBuildAction (org.gradle.launcher.cli)
execute:207, Actions$RunnableActionAdapter (org.gradle.internal)
execute:402, CommandLineActionFactory$ParseAndBuildAction (org.gradle.launcher.cli)
execute:375, CommandLineActionFactory$ParseAndBuildAction (org.gradle.launcher.cli)
execute:37, ExceptionReportingAction (org.gradle.launcher.cli)
execute:23, ExceptionReportingAction (org.gradle.launcher.cli)
execute:368, CommandLineActionFactory$WithLogging (org.gradle.launcher.cli)
execute:298, CommandLineActionFactory$WithLogging (org.gradle.launcher.cli)
doAction:36, Main (org.gradle.launcher)
run:45, EntryPoint (org.gradle.launcher.bootstrap)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
runNoExit:60, ProcessBootstrap (org.gradle.launcher.bootstrap)
run:37, ProcessBootstrap (org.gradle.launcher.bootstrap)
main:23, GradleMain (org.gradle.launcher)
There is no my code in main thread or other threads. However, if I check process list, it seems there is no standalone jvm process for tomcat.
And when the program is paused, I can still visit the page while the output in console is paused.
With GRADL_OPTS
set as such - you are launching debug process for the Gradle daemon itself not for the forked Java process where the Tomcat server actually runs.
You can use Gradle Run/Debug Configuration for starting Tomcat server where you specify the JVM options for the forked process:
The screenshot is taken from this article: Debugging a spring-mvc web-app with the gradle-tomcat-plugin and IntelliJ IDEA