Adding options, such as -runjdb, at runtime using the CLI or gradle plugin

I was having an issue attaching a debugger when trying to run in VS Code while using the Gradle plugins. I tried to debug the extensions to see what was wrong. I finally realized the issue, I was adding the debug option to the wrong place. I attempted the following 3 commands:

./gradlew subproject:run.bndrunfile -Dorg.gradle.debug.port=5005 -Dorg.gradle.debug=true
./gradlew run -Dorg.gradle.debug.port=5005 -Dorg.gradle.debug=true # run is a aQute.bnd.gradle.Bndrun task using bndrunfile.bndrun
java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=\\*:5005 bnd.jar run subproject/bndrunfile.bndrun

I was able to attach a debugger at port 5005, so why was it not suspending my code at set breakpoints? I assumed there was a problem with my classpaths or source files.

I realized after finally finding -runjdb=5005 and setting that in the bndrun file that my issue all along was that, though a JDWP transport interface was being established, it wasn’t established for the VM running OSGi, but, in 2 instances, Gradle, and in the other, the Java command to run the bnd.jar but not the VM established by the jar itself. I believed I had set -runvm with the agentlib argument at some point but I can’t recall.

In any case, it seems obvious in hindsight. What I’d like to know now, is can I set -runjdb or other run properties when running from command line? I found a topic regarding doing so with maven, but haven’t seen anything to that effect for Gradle, or through running the bnd from the command line directly. I know I could effectively extend the bndrun file with -include in a new bndrun and add the -runjdb option, thus separating my production run which is later exported and my development/debugging bndrun, but I already have quite a few bndrun files in my workspace for different machine instances.

I’m sorry if the answer obvious. I assumed I could perhaps use -Drunjdb for instance, and perhaps it’s a Gradle usage issue and not something I should bothering everyone here with, but maybe it’ll help someone else in the future.

Thanks for the help!

You could try to add this to build.gradle:

tasks.withType(JavaExec) {
    jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
}