feat(gradle): debug forked JVMs on a dynamic JDWP port (#2154)

Debugging a Gradle test worker or Spring Boot application attached through a fixed --debug-jvm port, so concurrent runs collided. The forked JVM now gets a dynamic JDWP address for Test tasks and BootRun, and the init scripts attach to the selected port. An agent the build configures itself (jvmArgs or debug = true) is replaced, so the JVM has one agent; a plain Run has none.

Co-authored-by: misswell <28730815+misswell@users.noreply.github.com>
This commit is contained in:
misswell
2026-11-09 01:15:23 +08:00
committed by GitHub
co-authored by misswell
parent a73e3c21ad
commit 4139cb64c2
9 changed files with 113 additions and 6 deletions
+6
View File
@@ -63,6 +63,12 @@ export function jdwpLaunch(config: RunConfig): RunConfig | null {
// A delegated Application: its init script adds the agent (port 0) to the JavaExec JVM.
if (args.some((a) => a.startsWith(DELEGATED_MAIN)))
return args.includes(DELEGATED_DEBUG) ? config : { ...config, args: [...args, DELEGATED_DEBUG] };
// Gradle Test forks test workers: the init script gives them a dynamic JDWP port.
if (config.isTest || args.some((a) => /(^|:)(test|integrationTest)$/.test(a)))
return args.includes(DELEGATED_DEBUG) ? config : { ...config, args: [...args, DELEGATED_DEBUG] };
// BootRun's init script gives the forked application JVM a dynamic port.
if (args.some((a) => /(^|:)bootRun$/.test(a)))
return args.includes(DELEGATED_DEBUG) ? config : { ...config, args: [...args, DELEGATED_DEBUG] };
if (!args.some(isGradleJvmTask)) return null;
return args.includes("--debug-jvm") ? config : { ...config, args: [...args, "--debug-jvm"] };
}