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
This commit is contained in:
Andy Wilkinson 2024-06-27 12:55:15 +01:00
parent 3e98a932e0
commit d2f74426f7

View File

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