From d2f74426f74333b9a27e6a3150d124b46953cfa9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 27 Jun 2024 12:55:15 +0100 Subject: [PATCH] Work around bug in Gradle's Eclipse model The model incorrectly marks the Gradle API and all of its dependencies as test dependencies, making them unavailable in Eclipse to code in src/main/java. We work around this by modifying the classpath container to remove the test attribute from the dependencies that should be available to main code. See gh-41228 --- .../spring-boot-gradle-plugin/build.gradle | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle index 385d08d1bbb..e491019a755 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle @@ -1,3 +1,7 @@ +import org.gradle.plugins.ide.eclipse.EclipsePlugin +import org.gradle.plugins.ide.eclipse.model.Classpath +import org.gradle.plugins.ide.eclipse.model.Library + plugins { id "java-gradle-plugin" id "maven-publish" @@ -219,3 +223,19 @@ publishing { } } } + +plugins.withType(EclipsePlugin) { + eclipse { + classpath.file { merger -> + merger.whenMerged { content -> + if (content instanceof Classpath) { + content.entries.each { entry -> + if (entry instanceof Library && (entry.path.contains("gradle-api-") || entry.path.contains("groovy-"))) { + entry.entryAttributes.remove("test") + } + } + } + } + } + } +}