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

Add to `-classpath` via dedicated configuration

Open f4lco opened this issue 3 years ago • 3 comments

First of all, thank you for this plugin, it is well documented and very useful 🎉

I have a minor feature to add: is it possible to add to the -classpath argument via a dedicated configuration?

Let me expand: I tried to use a JAXB plugin and ran into the following problem, where the service loader complains that the requested plugin is not actually an instance of com.sun.tools.xjc.Plugin. The root cause are different classloaders for Plugin and the class that is supposed to be a subtype. The solution is that all plugin JARs must be on the list of -classpath (an argument XJC), and not on the regular classpath from java -cp. See also https://stackoverflow.com/a/28197814.

With the current plugin, one can only add to -classpath by adding dependencies to the compile classpath:

https://github.com/IntershopCommunicationsAG/jaxb-gradle-plugin/blob/a058faef90014f293fca08f32563d43ad6ccc7dc/src/main/kotlin/com/intershop/gradle/jaxb/task/SchemaToJavaTask.kt#L392-L395

resp.

https://github.com/IntershopCommunicationsAG/jaxb-gradle-plugin/blob/a058faef90014f293fca08f32563d43ad6ccc7dc/src/main/kotlin/com/intershop/gradle/jaxb/task/SchemaToJavaTask.kt#L326-L332

However, I would prefer not to add JAXB plugins to my implementation configuration (or to generally have the JAXB plugin and its dependencies on the compile classpath).

  • I would suggest to add a dedicated configuration for plugins, like jaxbPlugins, and use that in addition to compileClasspath.
  • Would you accept a PR for that?

f4lco avatar Apr 30 '21 12:04 f4lco

It is not really visible in the documentation: "It is possible to overwrite the project dependency configuration 'jaxb', if you want use an other version of JAXB. The classpath of the xjc can be extended with a project configuration 'jaxb' and dependencies." So it is possible to replace all necessary dependencies in the jaxb configuration. That is necessary for the tooling. The class path is necessary for the code generation self and is the xjc parameter -classpath. Do you want a separate class path configuration for these files?

m-raab avatar Apr 30 '21 16:04 m-raab

I think I understand your problem. I will check that in the next release.

m-raab avatar Apr 30 '21 16:04 m-raab

Thank you very much @m-raab, looking forward to it. Actually, I saw the relevant documentation, but it does not address the problem, because the existing dependency configurations do not add to -classpath (maybe that is a bit clearer).

f4lco avatar May 04 '21 07:05 f4lco