xjc-gradle-plugin icon indicating copy to clipboard operation
xjc-gradle-plugin copied to clipboard

`outputJavaDir` and `defaultPackage` don't propagate correctly to groups

Open Michionlion opened this issue 11 months ago • 0 comments

For a configuration like:

xjc {
  xjcVersion.set "3.0.2"
  useJakarta.set true
  xsdDir.set file("src/main/resources/xsd")
  outputJavaDir.set file("src/model/java")

  groups {
    register("Thing") {
      includes.add "Thing.xsd"
      defaultPackage.set "com.stuff.messages"
    }
    register("In") {
      includes.add "In.xsd"
      defaultPackage.set "com.stuff.messages.in"
    }
  }
}

I would expect the generates files to appear in src/model/java/com/stuff/messages and src/model/java/com/stuff/messages/in. However, instead they land under build/generated/sources/xjc-<group-name>. Notably, they have the correct file structure inside that directory, including correct package declarations set from defaultPackage.

If I add outputJavaDir.set file("src/model/java") to each group (without removing the one set outside groups) , then all files get dumped in src/model/java/com/stuff/messages (even ones that should be in the deeper in/ folder, and package declarations are all set to com.stuff.messages. Notably, the printed paths for each generated class are correct, and show the extended com/stuff/messages/in/Class.java path.

If I further specify the actual package path in each group, like outputJavaDir.set file("src/model/java/com/stuff/messages/in") for the in group, then the same thing happens as before -- package declarations are still all com.stuff.messages, but now all files are dumped in src/model/java/com/stuff/messages/com/stuff/messages (note the repeated package structure).

The example here is a bit simplified, but I think the issues primarily come from the fact that the destination packages and/or folders are nested in each other, and so creation (and deletion) order matters -- for instance, if the In group starts generating first, deleting src/model/java/com/stuff/messages/in and then proceeding to start populating it (which I did see happen, some of the deeper packages would get their directories created, but then would end up being destroyed), but then com.stuff.messages starts generating and deletes src/model/java/com/stuff/messages, we'd run into a problem. What's weird is it does seem like all the types are generated in the final folder (although that may not be the case, it's hard to tell from what I'm running), which means something more complicated is going on.

I ended up just having them all generate in the correct structure under build, and copying them to where I needed the source code to be.

Michionlion avatar Jul 19 '23 19:07 Michionlion