Skip to content

Set maven.multiModuleProjectDirectory as system property#3761

Open
chagong wants to merge 1 commit intoeclipse-jdtls:mainfrom
chagong:fix/set-multiModuleProjectDirectory-sysprop
Open

Set maven.multiModuleProjectDirectory as system property#3761
chagong wants to merge 1 commit intoeclipse-jdtls:mainfrom
chagong:fix/set-multiModuleProjectDirectory-sysprop

Conversation

@chagong
Copy link
Copy Markdown
Contributor

@chagong chagong commented Apr 15, 2026

Problem

Projects that reference ${maven.multiModuleProjectDirectory} in their POM fail to import because the property is never interpolated. The Maven CLI launcher (mvn) sets this as a JVM system property via -Dmaven.multiModuleProjectDirectory=..., but JDTLS does not.

JDTLS already computes the value correctly in StandardPreferenceManager and injects it as a Maven profile property. However, m2e's MavenExecutionContext.populateSystemProperties() reads from System.getProperties(), not profile properties. So ${maven.multiModuleProjectDirectory} remains unresolved during Maven model building.

Affected projects

  • Apache Dubbo — parent POM uses <directory>${maven.multiModuleProjectDirectory}</directory> in <resources>
  • Google Guava — same pattern
  • Any project referencing ${maven.multiModuleProjectDirectory} in POM expressions

Error

org.eclipse.core.runtime.CoreException: Could not update project dubbo-common configuration
Caused by: java.lang.IllegalArgumentException: Path must include project and resource name: /
    at org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.getFolder(AbstractJavaProjectConfigurator.java:1007)
    at org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.addResourceDirs(AbstractJavaProjectConfigurator.java:639)
    ...

Result: project loses Java nature — The 'dubbo-common' project has no .classpath. Removing Java nature and builder.

Fix

Call System.setProperty(MAVEN_MULTI_MODULE_PROJECT_DIRECTORY, multiModuleProjectDirectory) in StandardPreferenceManager after computing the value, only when the property isn't already set externally. This mirrors the mvn launcher behavior.

Note: There is also a downstream bug in m2e's AbstractJavaProjectConfigurator.getFolder() that crashes when a resolved resource directory is an ancestor of the project — fix submitted as eclipse-m2e/m2e-core#2160. Both fixes are needed for full resolution.

Fixes #3760

@eclipse-ls-bot
Copy link
Copy Markdown
Contributor

Can one of the admins verify this patch?

The Maven CLI launcher sets maven.multiModuleProjectDirectory as a JVM
system property (-D) pointing to the directory containing .mvn/. JDTLS
computes this value and injects it as a Maven profile property, but
m2e's MavenExecutionContext.populateSystemProperties() reads from
System.getProperties(), not from profile properties.

This means  in POMs remains
unresolved during model building, breaking projects like Apache Dubbo
and Google Guava that use it in resource directory paths.

Set the property via System.setProperty() to mirror the mvn launcher
behavior. This is only done when the property isn't already set
externally.

Fixes eclipse-jdtls#3760

Signed-off-by: Changyong Gong <chagon@microsoft.com>
@chagong chagong force-pushed the fix/set-multiModuleProjectDirectory-sysprop branch from 0a9b603 to 5813cc0 Compare April 15, 2026 02:18
@fbricon
Copy link
Copy Markdown
Contributor

fbricon commented Apr 16, 2026

add to whitelist

@fbricon
Copy link
Copy Markdown
Contributor

fbricon commented Apr 16, 2026

@snjeza can you please review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

maven.multiModuleProjectDirectory system property not set — breaks projects using it in POM

3 participants