-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Referencing classes in Gradle's API jar that are also in the JDK cause compilation errors in Eclipse when building with Java 9 and later #19577
Comments
Also having this issue. Our suite of Gradle plugins doesn't compile when imported with Eclipse Buildship and JDK 11. I can workaround this issue by limiting the module path of the Eclipse projects using the code below. The projects will compile now when "javax.xml" module is excluded. Is there any way to get this working in Eclipse and JDK 11? It seems to be working in Intellij IDEA.
|
Also have same issue, after finally being able to lift project baseline to Java 11. Everywhere we have custom Gradle tasks present and thus have the gradle API jar in the compile classpath. As we use the xml APIs, the java.xml module is required. |
I see the same problem trying to work on Gradle plugins in Eclipse targeting java 17. Fortunately, it is possible to work around. The below works for me with Gradle 8.2.1, java 17, and Eclipse 2023-03. // Workaround for https://github.com/gradle/gradle/issues/19577
//
// Makes a shaded copy of the gradle-api jar-file and switches the Eclipse classpath to use it.
// There is a per-root-project shaded file to allow for different shading configurations in different projects.
task makeShadedGradleApi(type: Zip) {
def gradleVersion = project.gradle.gradleVersion
def cacheDir = project.gradle.gradleUserHomeDir.toPath().resolve('caches').resolve(gradleVersion).resolve('generated-gradle-jars')
def fileName = 'shaded-api-' + Integer.toHexString(project.rootDir.hashCode()) + '.jar'
def shadedApiFile = cacheDir.resolve(fileName).toFile()
def apiFile = cacheDir.resolve('gradle-api-' + gradleVersion + '.jar')
archiveFile.set(shadedApiFile)
from project.zipTree(apiFile)
exclude "org/w3c/**/*"
doFirst {
logger.lifecycle("Shading $apiFile into $shadedApiFile")
}
}
tasks.eclipseClasspath.dependsOn(makeShadedGradleApi)
eclipse {
classpath {
file {
withXml {
def cp = it.asNode()
// Replace gradle-api library dependency with the shaded archive
cp
.classpathentry
.findAll { e -> e.@kind == 'lib' && e.@path.contains('gradle-api') }
.each { e ->
def c = e.clone()
c.@path = tasks.makeShadedGradleApi.archivePath
cp.remove(e)
cp.append(c)
}
}
}
}
} |
I am out of the office until 31-07-2023.
Please contact InfoSuite support at ***@***.*** for assistance.
Note: This is an automated response to your message "Re: [gradle/gradle] Referencing classes in Gradle's API jar that are also in the JDK cause compilation errors in Eclipse when building with Java 9 and later (Issue #19577)"( sent on 26-07-2023 13:41:00) .
This is the only notification you will receive while this person is away.
|
Expected Behavior
A project that depends on Gradle's API jar should build cleanly in Eclipse when using Java 9+.
Current Behavior
Compilation fails when trying to, for example, use code in
javax.xml.parsers
due to the package being split between the unnamed andjava.xml
modules.Context
The generated Gradle API jar contains packages and classes that are part of the JDK. These split packages cause compilation failures in Eclipse. It does not fail on the command line which, as per this mailing list discussion, is due to a bug in the JDK. When the JDK bug is fixed, similar failures will occur with
javac
.This problem prevents compilation of Spring Boot's
buildSrc
on its current main branch in Eclipse. OurbuildSrc
plugins use code in variousjavax.xml
packages and it does not compile in Eclipse with Java 17.IMO, Gradle's API jar should not contain classes and packages that are also part of the JDK.
Steps to Reproduce
Import the project in this zip file into Eclipse. I'm using 2021-09 but I believe it'll occur in other versions of Eclipse as well. You should see two errors:
Your Environment
Build scan URL: scans.gradle.com is unavailable
I don't think this problem is environment-specific. FWIW, I'm using Eclipse 2021-09 on macOS with Temurin-17+35 (build 17+35).
The text was updated successfully, but these errors were encountered: