Compare commits

...
Author SHA1 Message Date
l0ng-ai 08cfd8ece3 feat(maven): Always update snapshots setting
Settings › Build Tools › Maven gets "Always update snapshots" (off by
default, Global or This project). On, Maven runs, builds and syncs get -U
and jdtls imports with java.maven.updateSnapshots, so newer SNAPSHOT
dependencies are picked up from remote repositories. A run configuration
that already passes -U or --update-snapshots keeps its own flag.
2026-11-19 18:16:56 +08:00
10 changed files with 66 additions and 8 deletions

No files matched your search

+3
View File
@@ -1535,6 +1535,9 @@ pub struct MavenSettings {
/// project (jdtls `java.maven.downloadSources`). Off: sources are fetched on demand
/// from a library class's Download Sources banner.
pub download_sources: bool,
/// Always update snapshots (`-U`): Maven checks remote repositories for newer SNAPSHOT
/// dependencies on every sync, build and run, and jdtls on import (`java.maven.updateSnapshots`).
pub update_snapshots: bool,
}
impl MavenSettings {
+16 -6
View File
@@ -537,18 +537,21 @@ pub fn configure_gradle_runtime(cfg: &mut LanguageServerConfig, root: &Path, bui
merge(cfg.settings.get_or_insert_with(|| json!({})), json!({"java": {"import": {"gradle": gradle}}}));
}
/// Settings › Build Tools › Maven › Automatically download sources → jdtls
/// `java.maven.downloadSources`.
/// Settings › Build Tools › Maven › Automatically download sources and Always update
/// snapshots → jdtls `java.maven.downloadSources` / `java.maven.updateSnapshots`.
pub fn configure_maven_sources(cfg: &mut LanguageServerConfig, s: &Settings) {
if cfg.name != "jdtls" {
return;
}
let download = s.languages.java.maven.download_sources;
merge(cfg.settings.get_or_insert_with(|| json!({})), json!({"java": {"maven": {"downloadSources": download}}}));
let m = &s.languages.java.maven;
merge(
cfg.settings.get_or_insert_with(|| json!({})),
json!({"java": {"maven": {"downloadSources": m.download_sources, "updateSnapshots": m.update_snapshots}}}),
);
}
/// Maven options from settings, placed before the goals: `-s <settings.xml>`,
/// `-t <toolchains.xml>`, `-Dmaven.repo.local=<dir>`, `-T <count>` and `-P <profiles>`.
/// `-t <toolchains.xml>`, `-Dmaven.repo.local=<dir>`, `-T <count>`, `-P <profiles>` and `-U`.
pub fn maven_options(root: &Path, s: &Settings) -> Vec<String> {
let m = &s.languages.java.maven;
let mut out = Vec::new();
@@ -567,6 +570,9 @@ pub fn maven_options(root: &Path, s: &Settings) -> Vec<String> {
if let Some(profiles) = non_empty(&m.active_profiles) {
out.extend(["-P".to_owned(), profiles.to_owned()]);
}
if m.update_snapshots {
out.push("-U".to_owned());
}
out
}
@@ -1647,6 +1653,9 @@ fn maven_option_flag(arg: &str) -> Option<&'static str> {
return Some(short);
}
}
if arg == "-U" || arg == "--update-snapshots" {
return Some("-U");
}
arg.starts_with("-Dmaven.repo.local=").then_some("-Dmaven.repo.local")
}
@@ -2466,8 +2475,9 @@ mod maven_linkage_tests {
Some(json!({"java": {"maven": {"downloadSources": false, "updateSnapshots": false}}}))
);
settings.languages.java.maven.download_sources = true;
settings.languages.java.maven.update_snapshots = true;
configure_maven_sources(&mut cfg, &settings);
assert_eq!(cfg.settings.unwrap()["java"]["maven"]["downloadSources"], json!(true));
assert_eq!(cfg.settings.unwrap()["java"]["maven"], json!({"downloadSources": true, "updateSnapshots": true}));
let mut other = custom_server("kotlin", &LanguageServerSettings::default());
configure_maven_sources(&mut other, &settings);
+20
View File
@@ -887,6 +887,26 @@ fn maven_options_carry_active_profiles_into_the_command_line() {
assert_eq!(configured[0].args, ["-P", "prod", "package"]);
}
#[test]
fn always_update_snapshots_adds_dash_u_once() {
let tmp = tempfile::tempdir().unwrap();
let mut s = Settings::default();
s.languages.java.maven.update_snapshots = true;
assert_eq!(maven_options(tmp.path(), &s), ["-U"]);
let mut configs = vec![run("maven", "./mvnw", &["package"])];
for _ in 0..2 {
apply_to_run_configs(&mut configs, tmp.path(), &s);
assert_eq!(configs[0].args, ["-U", "package"]);
}
let mut own = vec![run("maven", "./mvnw", &["--update-snapshots", "package"])];
apply_to_run_configs(&mut own, tmp.path(), &s);
assert_eq!(own[0].args, ["--update-snapshots", "package"]);
s.languages.java.maven.update_snapshots = false;
apply_to_run_configs(&mut configs, tmp.path(), &s);
assert_eq!(configs[0].args, ["package"]);
}
#[test]
fn maven_profile_and_toolchain_overrides_accept_every_option_form() {
let tmp = tempfile::tempdir().unwrap();
+5
View File
@@ -8378,6 +8378,11 @@ export type MavenSettings = {
* from a library class's Download Sources banner.
*/
downloadSources?: boolean,
/**
* Always update snapshots (`-U`): Maven checks remote repositories for newer SNAPSHOT
* dependencies on every sync, build and run, and jdtls on import (`java.maven.updateSnapshots`).
*/
updateSnapshots?: boolean,
};
/** Summary of one server discovered inside an external MCP configuration file. */
@@ -65,6 +65,7 @@ describe("languages settings", () => {
activeProfiles: "",
delegateBuild: false,
downloadSources: false,
updateSnapshots: false,
});
expect(validateSettings({}).languages).toEqual(DEFAULT_LANGUAGES);
expect(validateLanguages({ java: { maven: { threads: 4 } } }).java.maven.threads).toBe("");
@@ -77,6 +78,7 @@ describe("languages settings", () => {
expect(validateLanguages({ java: { maven: { delegateBuild: true } } }).java.maven.delegateBuild).toBe(true);
expect(validateLanguages({ java: { maven: { delegateBuild: "yes" } } }).java.maven.delegateBuild).toBe(false);
expect(validateLanguages({ java: { maven: { downloadSources: true } } }).java.maven.downloadSources).toBe(true);
expect(validateLanguages({ java: { maven: { updateSnapshots: true } } }).java.maven.updateSnapshots).toBe(true);
const settings = validateSettings({ languages: { java: { maven: { runnerJre: " ./jdks/21 " } } } });
expect(validateSettings(settings).languages.java.maven.runnerJre).toBe("./jdks/21");
});
@@ -564,6 +564,7 @@ export function MavenPage() {
const [delegateBuild, setDelegateBuild] = useSetting<boolean>("languages.java.maven.delegateBuild");
const [daemon, setDaemon] = useSetting<boolean>("languages.java.maven.daemon");
const [downloadSources, setDownloadSources] = useSetting<boolean>("languages.java.maven.downloadSources");
const [updateSnapshots, setUpdateSnapshots] = useSetting<boolean>("languages.java.maven.updateSnapshots");
const [threads, setThreads] = useSetting<string>("languages.java.maven.threads");
const [activeProfiles, setActiveProfiles] = useSetting<string>("languages.java.maven.activeProfiles");
const id = useId();
@@ -582,6 +583,12 @@ export function MavenPage() {
onChange={setDownloadSources}
hint="The Java language server downloads the sources of all dependencies when it imports the project. When off, a library class opens decompiled and its Download Sources banner fetches the sources of that library only."
/>
<Toggle
label="Always update snapshots"
checked={updateSnapshots}
onChange={setUpdateSnapshots}
hint="Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U)."
/>
<SdkRow
k="languages.java.maven.runnerJre"
label="JRE"
@@ -215,6 +215,9 @@ export const EXECUTION_PAGES: PageSpec[] = [
"threads",
"-T",
"parallel",
"Always update snapshots",
"SNAPSHOT",
"-U",
],
component: MavenPage,
},
+4
View File
@@ -234,6 +234,8 @@ export interface LanguagesValid {
delegateBuild: boolean;
/** Download dependencies' `-sources.jar` when jdtls imports the project. */
downloadSources: boolean;
/** Always update snapshots: `-U` on Maven runs, `java.maven.updateSnapshots` for jdtls. */
updateSnapshots: boolean;
};
};
/** Preview font size in px; `null` follows the editor font size. */
@@ -324,6 +326,7 @@ export const DEFAULT_LANGUAGES: LanguagesValid = {
activeProfiles: "",
delegateBuild: false,
downloadSources: false,
updateSnapshots: false,
},
},
markdown: { previewFontSize: null },
@@ -504,6 +507,7 @@ export function validateLanguages(raw: unknown): LanguagesValid {
activeProfiles: text(maven.activeProfiles, d.java.maven.activeProfiles),
delegateBuild: bool(maven.delegateBuild, d.java.maven.delegateBuild),
downloadSources: bool(maven.downloadSources, d.java.maven.downloadSources),
updateSnapshots: bool(maven.updateSnapshots, d.java.maven.updateSnapshots),
},
},
markdown: { previewFontSize: previewSize(markdown.previewFontSize) },
+3 -1
View File
@@ -2646,5 +2646,7 @@
"File '{name}' already exists. Do you want to overwrite it?": "File '{name}' already exists. Do you want to overwrite it?",
"{path} is a directory": "{path} is a directory",
"Cannot export test results": "Cannot export test results",
"Test results exported": "Test results exported"
"Test results exported": "Test results exported",
"Always update snapshots": "Always update snapshots",
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U)."
}
+3 -1
View File
@@ -9025,5 +9025,7 @@
"File '{name}' already exists. Do you want to overwrite it?": "文件 '{name}' 已存在。是否覆盖?",
"{path} is a directory": "{path} 是目录",
"Cannot export test results": "无法导出测试结果",
"Test results exported": "测试结果已导出"
"Test results exported": "测试结果已导出",
"Always update snapshots": "始终更新快照",
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "每次同步、构建和运行时都检查远程仓库中是否有更新的 SNAPSHOT 依赖(-U)。"
}