Gradle docs say there is a --debug-jvm option, but when I tried it the result was an error:
Unknown command-line option '--debug-jvm'.
Gradle 7.4.2 on JDK 17.0.3
What is the trick to make it work?
Gradle docs say there is a --debug-jvm option, but when I tried it the result was an error:
Unknown command-line option '--debug-jvm'.
Gradle 7.4.2 on JDK 17.0.3
What is the trick to make it work?
The --debug-jvm
option is specifically for running the JVM forked by a Test
or JavaExec
task so that you can attach a debugger. It is a task command-line option which means that it can only immediately follow the task that it applies to. i.e. gradle test --debug-jvm
but NOT gradle build --debug-jvm
even though build
depends on test
.
That is how I’m using it, when running a JavaExec task. Specifically a task intended to run a specific main class that it gets from a property. The task is called runSingle
- it is usually injected by NetBeans’ Gradle support, but I have defined it myself because I also need to set some system properties when running the Java code. It works fine for running normally, but fails with the --debug-jvm
option.
There’s not likely enough information here to come to any conclusions. I haven’t been able to figure any way to break it accidentally with the details given unless I intentionally don’t pass the arguments with the correct tasks/order. i.e. gradle --debug-jvm runSingle -PmainClass=Main
instead of gradle runSingle --debug-jvm -PmainClass=Main