I’m stumbling through converting a Maven build to Gradle. The build has to generate code with XJC and compile and package the generated and custom source together. I believe I’m generating the source correctly now, but I’m still trying to figure out the proper way to compile the generated source along with the custom source. After this, I’ll have to package up a WAR and EAR, but I’ll deal with those one step at a time.
I am using the user guide as a resource, but I’m finding the user guide does a good job of “listing” things (and formats them badly in the PDF sometimes), but it seems to fall short in describing how to actually do things. I also found references in the forum, but some of those references are quite old, and I’m not sure if they’re still valid.
This is an excerpt of my current build script. This currently barfs on my futile attempt to add to the compile classpath (the line is marked).
Don’t hesitate to give general advice about other things that you see here.
Understood. Rather than defining a new source set (which in turn defines a compile task), I’d suggest simply adding the generated source to the existing ‘compileJava’ task. This has the benefit of putting all the class output in the same location (which is then used by the ‘jar’ task), as well as inheriting the production source classpath. I’d also suggest having your XJC task place your generated source somewhere in your build directory. Makes cleaning your project easier and doesn’t pollute your version controlled folders.
Hmm. Seeing something I don’t understand yet. My generated classes declare nested static classes, often 2-3 classes deep, and my custom code imports some of those classes, using the fully qualified name, like “…DatasourceStatus.Datasources.Datasource.Results.Result”. When I inspect the classes compiled by Eclipse and my Maven build, these classes look fine. However, when I inspect the classes built by Gradle, and from manually constructed “javac” lines (based on the debug info from Gradle), I only see the following classes:
DatasourceStatus
DatasourceStatus$Datasource
DatasourceStatus$Datasource$Results
DatasourceStatus$Datasource$Results$Result
The classes generated by Maven and Eclipse are these:
You might want to try using a diff tool to compare the Gradle generated sources versus the Maven ones to see if there are any strange subtle differences. I can’t think of anything off hand that would case the behavior you’re seeing.
Duh. Should have thought of that. I see differences that explain this. I guess my upgrades of JAXB libraries and extensions have resulted in changes in the resulting output. Time to dig that up again.