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) }