Fix XJC configuration to re-enable Eclipse IDE support

Our recent switch from the `org.unbroken-dome.xjc` plugin to the
`com.github.bjornvester.xjc` plugin resulted in errors when trying to
import Spring Framework projects into the Eclipse IDE.

This commit fixes those issues as follows.

- @wilkinsona revised the XJC configuration in `spring-oxm.gradle` to
  avoid the ConcurrentModificationException encountered when running
  `./gradlew eclipse`.

- I added a workaround in `ide.gradle` to manually remove lingering
  "main" classpath entries for sources generated by XJC.

Co-authored-by: Andy Wilkinson <andy.wilkinson@broadcom.com>

Closes gh-33264
This commit is contained in:
Sam Brannen 2024-07-26 16:39:40 +03:00
parent 9aac24c18a
commit 5aa38833dd
2 changed files with 20 additions and 9 deletions

View File

@ -77,6 +77,19 @@ eclipse.classpath.file.whenMerged {
} }
} }
// Due to an apparent bug in Gradle, even though we exclude the "main" classpath
// entries for sources generated by XJC in spring-oxm.gradle, the Gradle eclipse
// plugin still includes them in the generated .classpath file. So, we have to
// manually remove those lingering "main" entries.
if (project.name == "spring-oxm") {
eclipse.classpath.file.whenMerged { classpath ->
classpath.entries.removeAll {
it.path =~ /build\/generated\/sources\/xjc\/.+/ &&
it.entryAttributes.get("gradle_scope") == "main"
}
}
}
// Include project specific settings // Include project specific settings
task eclipseSettings(type: Copy) { task eclipseSettings(type: Copy) {
from rootProject.files( from rootProject.files(

View File

@ -20,7 +20,6 @@ dependencies {
testImplementation("org.codehaus.jettison:jettison") { testImplementation("org.codehaus.jettison:jettison") {
exclude group: "stax", module: "stax-api" exclude group: "stax", module: "stax-api"
} }
//testImplementation(files(genJaxb.classesDir).builtBy(genJaxb))
testImplementation("org.xmlunit:xmlunit-assertj") testImplementation("org.xmlunit:xmlunit-assertj")
testImplementation("org.xmlunit:xmlunit-matchers") testImplementation("org.xmlunit:xmlunit-matchers")
testRuntimeOnly("com.sun.xml.bind:jaxb-core") testRuntimeOnly("com.sun.xml.bind:jaxb-core")
@ -28,14 +27,13 @@ dependencies {
} }
tasks.named("xjc").configure { xjc -> tasks.named("xjc").configure { xjc ->
// XJC plugin only works against main sources // XJC plugin only works against main sources, so we have to "move" them to test sources.
def javaSrcDirs = sourceSets.main.java.srcDirs sourceSets.main.java.exclude {
javaSrcDirs.remove(file(xjc.outputJavaDir)) it.file.absolutePath.startsWith(outputJavaDir.get().asFile.absolutePath)
sourceSets.main.java.srcDirs = javaSrcDirs }
def resourcesSrcDirs = sourceSets.main.resources.srcDirs sourceSets.main.resources.exclude {
resourcesSrcDirs.remove(file(xjc.outputResourcesDir)) it.file.absolutePath.startsWith(outputResourcesDir.get().asFile.absolutePath)
sourceSets.main.resources.srcDirs = resourcesSrcDirs }
sourceSets.test.java.srcDir(xjc.outputJavaDir) sourceSets.test.java.srcDir(xjc.outputJavaDir)
sourceSets.test.resources.srcDir(xjc.outputResourcesDir) sourceSets.test.resources.srcDir(xjc.outputResourcesDir)
} }