fix(java): pass the configured Maven local repository to jdtls (#1813)

m2e resolves and downloads into maven.repo.local, which neither the
userSettings init option nor MAVEN_OPTS covers. Without it the embedded
Maven fell back to ~/.m2 even when every mvn run the IDE launches used
the configured repository, splitting the cache across two locations.

A -Dmaven.repo.local in the user's own jdtls VM options wins.

Fixes #1739
Цей коміт міститься в:
arookieofc authored and GitHub committed 2026-11-06 22:01:53 +08:00
1 джерело 8e5507b9f2
коміт 954ad354a1
2 files changed
+36

No files matched your search

+16
Переглянути файл
@@ -798,6 +798,22 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root
json!({ "settings": { "java": { "configuration": { "maven": { "userSettings": file } } } } }),
);
}
// m2e resolves and downloads into `maven.repo.local`; without it the
// embedded Maven falls back to ~/.m2 even when the IDE's own `mvn`
// runs honor the configured local repository. A `-Dmaven.repo.local`
// the user put in their own jdtls VM options wins.
if let Some(repo) = maven_local_repository(root, s) {
let arg = format!("-Dmaven.repo.local={}", repo.to_string_lossy());
let taken = cfg.args.iter().enumerate().any(|(i, a)| {
let value = a
.strip_prefix("--jvm-arg=")
.or_else(|| (i > 0 && cfg.args[i - 1] == "--jvm-arg").then_some(a.as_str()));
value.is_some_and(|a| a.split('=').next() == Some("-Dmaven.repo.local"))
});
if !taken {
cfg.args.push(format!("--jvm-arg={arg}"));
}
}
}
if let Some(lib) = tsdk(server_root, s).or_else(|| tsdk(root, s)) {
+20
Переглянути файл
@@ -115,6 +115,26 @@ fn jdtls_vm_args() {
assert_eq!(cfg.args, ["--jvm-arg=-Xmx2g", "--jvm-arg=-javaagent:/opt/lombok.jar"]);
}
#[test]
fn jdtls_honors_the_configured_maven_local_repository() {
let tmp = tempfile::tempdir().unwrap();
let repo = tmp.path().join("m2-repo");
let mut s = Settings::default();
s.languages.java.maven.local_repository = repo.to_string_lossy().into_owned();
let mut cfg = server("jdtls");
configure_server(&mut cfg, tmp.path(), tmp.path(), &s);
assert_eq!(cfg.args, [format!("--jvm-arg=-Dmaven.repo.local={}", repo.to_string_lossy())]);
// A `-Dmaven.repo.local` the user put in their own jdtls VM options wins.
s.languages.java.jdtls_vm_args = "-Xmx2g -Dmaven.repo.local=/user/repo".into();
let mut cfg = server("jdtls");
configure_server(&mut cfg, tmp.path(), tmp.path(), &s);
assert_eq!(cfg.args, ["--jvm-arg=-Xmx2g", "--jvm-arg=-Dmaven.repo.local=/user/repo"]);
// Unset: jdtls keeps m2e's own default (no arg at all).
let mut cfg = server("jdtls");
configure_server(&mut cfg, tmp.path(), tmp.path(), &Settings::default());
assert!(cfg.args.iter().all(|a| !a.contains("maven.repo.local")));
}
#[test]
fn rust_analyzer_check_command_and_toolchain() {
if cfg!(windows) {