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 <[email protected]>
Цей коміт міститься в:
misswellтаmisswell authored and GitHub committed 2026-11-09 01:15:23 +08:00
1 джерело a73e3c21ad
коміт 4139cb64c2
9 files changed
+113 -6

No files matched your search

+6
Переглянути файл
@@ -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"] };
}