From 5aa38833dddf427c3d702930bf1678a126806191 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:39:40 +0300 Subject: [PATCH] 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 Closes gh-33264 --- gradle/ide.gradle | 13 +++++++++++++ spring-oxm/spring-oxm.gradle | 16 +++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gradle/ide.gradle b/gradle/ide.gradle index 316d7634fc..517e4af6c2 100644 --- a/gradle/ide.gradle +++ b/gradle/ide.gradle @@ -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 task eclipseSettings(type: Copy) { from rootProject.files( diff --git a/spring-oxm/spring-oxm.gradle b/spring-oxm/spring-oxm.gradle index b23759e4b9..dea37ac797 100644 --- a/spring-oxm/spring-oxm.gradle +++ b/spring-oxm/spring-oxm.gradle @@ -20,7 +20,6 @@ dependencies { testImplementation("org.codehaus.jettison:jettison") { exclude group: "stax", module: "stax-api" } - //testImplementation(files(genJaxb.classesDir).builtBy(genJaxb)) testImplementation("org.xmlunit:xmlunit-assertj") testImplementation("org.xmlunit:xmlunit-matchers") testRuntimeOnly("com.sun.xml.bind:jaxb-core") @@ -28,14 +27,13 @@ dependencies { } tasks.named("xjc").configure { xjc -> - // XJC plugin only works against main sources - def javaSrcDirs = sourceSets.main.java.srcDirs - javaSrcDirs.remove(file(xjc.outputJavaDir)) - sourceSets.main.java.srcDirs = javaSrcDirs - def resourcesSrcDirs = sourceSets.main.resources.srcDirs - resourcesSrcDirs.remove(file(xjc.outputResourcesDir)) - sourceSets.main.resources.srcDirs = resourcesSrcDirs - + // XJC plugin only works against main sources, so we have to "move" them to test sources. + sourceSets.main.java.exclude { + it.file.absolutePath.startsWith(outputJavaDir.get().asFile.absolutePath) + } + sourceSets.main.resources.exclude { + it.file.absolutePath.startsWith(outputResourcesDir.get().asFile.absolutePath) + } sourceSets.test.java.srcDir(xjc.outputJavaDir) sourceSets.test.resources.srcDir(xjc.outputResourcesDir) }