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

+12 -5
Переглянути файл
@@ -49,14 +49,19 @@ export async function javaProjectName(root: string): Promise<string> {
const descriptor = await readText(join(root, ".project"));
const eclipse = /<name>([^<]+)<\/name>/.exec(descriptor)?.[1]?.trim();
if (eclipse) return eclipse;
const pom = await readText(join(root, "pom.xml"));
// A child module's own <artifactId> follows the <parent> block, which names the parent.
const own = pom.replace(/<parent>[\s\S]*?<\/parent>/, "");
const artifact = /<artifactId>\s*([^<\s]+)\s*<\/artifactId>/.exec(own)?.[1];
const artifact = /<artifactId>\s*([^<\s]+)\s*<\/artifactId>/.exec(ownPom(await readText(join(root, "pom.xml"))))?.[1];
if (artifact && !artifact.includes("${")) return artifact;
return baseName(root);
}
/** A child module's own part of its POM: its <artifactId> follows the <parent> block, which names the parent. */
const ownPom = (pom: string) => pom.replace(/<parent>[\s\S]*?<\/parent>/, "");
/** A dependency-only Maven module (`packaging=pom`): jdtls has no Java project for it. */
async function isPomOnlyModule(root: string): Promise<boolean> {
return /<packaging>\s*pom\s*<\/packaging>/.test(ownPom(await readText(join(root, "pom.xml"))));
}
/** A file of the project, or "" when it is missing (or when there is no filesystem bridge). */
async function readText(path: string): Promise<string> {
try {
@@ -224,7 +229,9 @@ export async function javaLaunchConfig(
// java-debug resolves the Java project for Evaluate on its own from `mainClass` only when
// the class belongs to a project it knows; name the project it imported so that works for
// classes compiled outside the language server's build (plain folders, custom outputs).
const project = await javaProjectName(info.projectRoot ?? root);
const projectRoot = info.projectRoot ?? join(root, module);
// A launch from a dependency-only POM names no project: java-debug finds the main class's own.
const project = (await isPomOnlyModule(projectRoot)) ? undefined : await javaProjectName(projectRoot);
return {
name: rc.name,
adapter: JAVA_ADAPTER,