Skip to content

Commit 5aa3883

Browse files
committed
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 <[email protected]> Closes gh-33264
1 parent 9aac24c commit 5aa3883

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

gradle/ide.gradle

+13
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ eclipse.classpath.file.whenMerged {
7777
}
7878
}
7979

80+
// Due to an apparent bug in Gradle, even though we exclude the "main" classpath
81+
// entries for sources generated by XJC in spring-oxm.gradle, the Gradle eclipse
82+
// plugin still includes them in the generated .classpath file. So, we have to
83+
// manually remove those lingering "main" entries.
84+
if (project.name == "spring-oxm") {
85+
eclipse.classpath.file.whenMerged { classpath ->
86+
classpath.entries.removeAll {
87+
it.path =~ /build\/generated\/sources\/xjc\/.+/ &&
88+
it.entryAttributes.get("gradle_scope") == "main"
89+
}
90+
}
91+
}
92+
8093
// Include project specific settings
8194
task eclipseSettings(type: Copy) {
8295
from rootProject.files(

spring-oxm/spring-oxm.gradle

+7-9
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@ dependencies {
2020
testImplementation("org.codehaus.jettison:jettison") {
2121
exclude group: "stax", module: "stax-api"
2222
}
23-
//testImplementation(files(genJaxb.classesDir).builtBy(genJaxb))
2423
testImplementation("org.xmlunit:xmlunit-assertj")
2524
testImplementation("org.xmlunit:xmlunit-matchers")
2625
testRuntimeOnly("com.sun.xml.bind:jaxb-core")
2726
testRuntimeOnly("com.sun.xml.bind:jaxb-impl")
2827
}
2928

3029
tasks.named("xjc").configure { xjc ->
31-
// XJC plugin only works against main sources
32-
def javaSrcDirs = sourceSets.main.java.srcDirs
33-
javaSrcDirs.remove(file(xjc.outputJavaDir))
34-
sourceSets.main.java.srcDirs = javaSrcDirs
35-
def resourcesSrcDirs = sourceSets.main.resources.srcDirs
36-
resourcesSrcDirs.remove(file(xjc.outputResourcesDir))
37-
sourceSets.main.resources.srcDirs = resourcesSrcDirs
38-
30+
// XJC plugin only works against main sources, so we have to "move" them to test sources.
31+
sourceSets.main.java.exclude {
32+
it.file.absolutePath.startsWith(outputJavaDir.get().asFile.absolutePath)
33+
}
34+
sourceSets.main.resources.exclude {
35+
it.file.absolutePath.startsWith(outputResourcesDir.get().asFile.absolutePath)
36+
}
3937
sourceSets.test.java.srcDir(xjc.outputJavaDir)
4038
sourceSets.test.resources.srcDir(xjc.outputResourcesDir)
4139
}

0 commit comments

Comments
 (0)