From 0d0de0183145b49f8f728c115b2b57f85fc41886 Mon Sep 17 00:00:00 2001 From: Jasmeet Singh Date: Sun, 1 Nov 2026 18:33:17 +0530 Subject: [PATCH] fix(java): re-sync jdtls after a Gradle sync so new dependencies resolve (#694) After a Gradle sync, build_sync did not send java/projectConfigurationsUpdate to jdtls (only the Maven path did), so jdtls kept its cached classpath and dependencies newly added to build.gradle stayed unresolved. The update is now sent for both Maven and Gradle, listing each project's build file. Co-authored-by: jasi381 <60892009+jasi381@users.noreply.github.com> --- crates/ide-host/src/ops/build.rs | 35 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/ide-host/src/ops/build.rs b/crates/ide-host/src/ops/build.rs index ad3983302..767875df5 100644 --- a/crates/ide-host/src/ops/build.rs +++ b/crates/ide-host/src/ops/build.rs @@ -133,22 +133,29 @@ pub async fn build_sync( host.end_request(request); let model = result??; if tool == BuildTool::Maven - && let Some(maven) = &model.maven + && model.maven.is_some() + && let Some(bridge) = &project.kotlin_bridge { - // jdtls re-imports on pom changes but misses artifacts added to ~/.m2 - // meanwhile ("missing artifact" stays until Invalidate Caches); asking it - // to update the project configurations re-resolves them (#436). - if let Some(bridge) = &project.kotlin_bridge { - bridge.configure_maven(offline, bridge_profiles); - } - let lsp = project.lsp.clone(); - let uris = maven.projects.iter().map(|p| ide_lsp::path_to_uri_string(&project.root.join(&p.pom))).collect(); - tokio::spawn(async move { - if let Err(e) = lsp.java_update_project_configs(&project.root, uris).await { - tracing::debug!("java/projectConfigurationsUpdate: {e}"); - } - }); + bridge.configure_maven(offline, bridge_profiles); } + // jdtls re-imports on pom changes but misses artifacts added to ~/.m2 + // meanwhile ("missing artifact" stays until Invalidate Caches); asking it + // to update the project configurations re-resolves them (#436). The same + // holds for Gradle: it reuses its cached classpath on restart, so a + // dependency added to `build.gradle` stays unresolved until told to sync. + let build_files: Vec = match tool { + BuildTool::Maven => model.maven.iter().flat_map(|m| m.projects.iter().map(|p| p.pom.clone())).collect(), + BuildTool::Gradle => { + model.gradle.iter().flat_map(|g| g.projects.iter().filter_map(|p| p.build_file.clone())).collect() + } + }; + let lsp = project.lsp.clone(); + let uris = build_files.iter().map(|f| ide_lsp::path_to_uri_string(&project.root.join(f))).collect(); + tokio::spawn(async move { + if let Err(e) = lsp.java_update_project_configs(&project.root, uris).await { + tracing::debug!("java/projectConfigurationsUpdate: {e}"); + } + }); Ok(model) }