Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(java): re-sync jdtls after a Gradle sync so new dependencies resolve (#694)

Jasmeet Singh0d0de0183145
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<String> = 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)
}