From af3e174702f48e2759f505d2b267fb5d8014de04 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 25 Nov 2026 04:37:46 +0800 Subject: [PATCH] fix(java): apply the Eclipse plugin to the project in the Gradle classpath init script (#5677) Inside the Gradle classpath init script's closures a bare `apply plugin: 'eclipse'` resolves to the init script's own apply. On Gradle 7 the Eclipse plugin then can't get its project services (no IdeArtifactRegistry), applying java fails, and jdtls's Gradle import fails for every Gradle 7 project, leaving all Java files red. The script now calls project.apply; a test keeps bare apply calls out of it. Fixes #5669 --- crates/ide-sdk/src/apply.rs | 10 ++++++++++ crates/ide-sdk/src/gradle-classpath.init.gradle | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ide-sdk/src/apply.rs b/crates/ide-sdk/src/apply.rs index 791c8b4470..30b357aec9 100644 --- a/crates/ide-sdk/src/apply.rs +++ b/crates/ide-sdk/src/apply.rs @@ -2796,6 +2796,16 @@ mod maven_linkage_tests { assert!(nowhere.settings.is_none(), "no usable directory: the import runs without it"); } + #[test] + fn gradle_classpath_script_applies_plugins_to_the_project() { + // Inside the script's closures a bare `apply` is the init script's own: on Gradle 7 the + // Eclipse plugin then fails to start and the whole import fails. + let script = include_str!("gradle-classpath.init.gradle"); + let bare: Vec<&str> = script.lines().filter(|line| line.trim_start().starts_with("apply ")).collect(); + assert!(bare.is_empty(), "{bare:?}"); + assert!(script.contains("project.apply plugin: 'eclipse'")); + } + #[test] fn gradle_import_of_a_gradle_build_runs_on_the_project_jdk_like_the_ides_builds() { let temp = tempfile::tempdir().unwrap(); diff --git a/crates/ide-sdk/src/gradle-classpath.init.gradle b/crates/ide-sdk/src/gradle-classpath.init.gradle index 68c89d4a37..60fc1e5cd7 100644 --- a/crates/ide-sdk/src/gradle-classpath.init.gradle +++ b/crates/ide-sdk/src/gradle-classpath.init.gradle @@ -3,7 +3,9 @@ // compile classpath names, so Java code sees the classes it compiles against. allprojects { plugins.withId('java') { - apply plugin: 'eclipse' + // `project.`: a bare `apply` in this closure is the init script's own (Gradle 7 fails to create the + // plugin then: no IdeArtifactRegistry service). + project.apply plugin: 'eclipse' eclipse.classpath.file.whenMerged { classpath -> def projectOf = { dep -> def path