fix(java): support launch classpaths from Maven POM modules (#6184)

An Application configuration whose classpath module is a dependency-only
Maven module (packaging=pom, such as a distribution or assembly module)
could not launch: launch preparation required the POM to be a Java
project in jdtls, and the Maven fallback rejected aggregators outright.

Such a module now resolves its launch classpath from its dependencies:
reactor modules (including runtime-scoped ones, which are now built as
upstream projects for every launch) and external libraries, without a
Java language server and without its own output directory. NoBuild
reuses the last resolved classpath instead of running the compile
lifecycle, and a launch from such a POM leaves the Java project to
java-debug instead of naming a non-Java project; a JDWP attach at an
aggregator root still names the root project.

Co-authored-by: solhovoy <[email protected]>
Цей коміт міститься в:
solhovoy authored and GitHub committed 2026-11-26 21:39:53 +08:00
1 джерело dc490f1017
коміт e44d7fd396
8 files changed
+288 -31

No files matched your search

+28 -1
Переглянути файл
@@ -3,6 +3,7 @@ import type { RunConfig } from "@/platform/ipc";
const invoked: Array<[string, unknown[]]> = [];
let shortenCommandLine: string | null = null;
let launchProjectRoot: string | undefined = "/p";
let kotlinFiles = false;
let debugAdapter = "java-debug";
const files: Record<string, string> = {};
@@ -45,7 +46,7 @@ vi.mock("@/platform/ipc", async (orig) => {
invoked.push(["javaResolveLaunch", a]);
return ok({
build: "succeeded",
projectRoot: "/p",
projectRoot: launchProjectRoot,
classPaths: ["/p/target/classes", "/m2/a.jar"],
modulePaths: [],
pathListSeparator: ":",
@@ -90,6 +91,7 @@ describe("Java debugging (java-debug through jdtls)", () => {
beforeEach(() => {
invoked.length = 0;
shortenCommandLine = null;
launchProjectRoot = "/p";
kotlinFiles = false;
debugAdapter = "java-debug";
});
@@ -273,6 +275,31 @@ describe("naming the Java project jdtls imported", () => {
expect(await javaProjectName("/p")).toBe("taihe");
});
it("lets java-debug resolve the main class instead of naming a POM-only project", async () => {
launchProjectRoot = undefined;
files["/p/assembly/pom.xml"] = "<project><artifactId>assembly</artifactId><packaging>pom</packaging></project>";
files["/p/assembly/.project"] = "<projectDescription><name>assembly</name></projectDescription>";
kotlinFiles = false;
debugAdapter = "java-debug";
const launch = await javaLaunchConfig({ ...app, module: "assembly" }, "/p");
expect(JSON.parse(launch.extraJson!)).not.toHaveProperty("projectName");
expect(JSON.parse(launch.extraJson!).classPaths).toEqual(["/p/target/classes", "/m2/a.jar"]);
});
it("still names the project of an aggregator root for a JDWP attach", async () => {
files["/p/pom.xml"] = "<project><artifactId>root</artifactId><packaging>pom</packaging></project>";
const attach = await javaAttachConfig({ name: "remote", module: "", hostName: "remote", port: 5005 }, "/p");
expect(JSON.parse(attach.extraJson!).projectName).toBe("root");
});
it("uses the configured Java module when the resolver does not report a project root", async () => {
launchProjectRoot = undefined;
files["/p/pom.xml"] = "<project><artifactId>root</artifactId><packaging>pom</packaging></project>";
files["/p/api/pom.xml"] = "<project><artifactId>api-module</artifactId></project>";
const launch = await javaLaunchConfig({ ...app, module: "api" }, "/p");
expect(JSON.parse(launch.extraJson!).projectName).toBe("api-module");
});
it("falls back to the folder name when the project says nothing, including unresolved properties", async () => {
expect(await javaProjectName("/p/api")).toBe("api");
files["/p/pom.xml"] = "<project><artifactId>${revision}</artifactId></project>";