Skip to content
Advertisement

How to provide JAXB dependency via Gradle package?

TLDR: Which packages (and with which scopes) does one has to include for:

  • using JAXB in a library
  • using XJC in a library
  • running tests in that library
  • include the library as a dependency into another library without having JAXB related runtime errors

Details:

I’m working with JAXB and XJC with JDK 16 and Gradle. I created a project A (namely bayern.steinbrecher:SepaXMLGenerator) which includes JAXB with the following snippet:

JavaScript

This works fine. I can even execute the included tests I created for project A.

However, if I try to use project A in another project B (namely bayern.steinbrecher:Green2) by including it via an implmentation declaration I get stuck by an error message telling me, the runtime dependency for JAXB was not found.

JavaScript

I am absolutely confused. I read many websites stating various different things of how to correctly include JAXB, Jakarta, Glassfish reference implementations or whatsoever and it seems like many of these websites are outdated partially since JAXB was initially included in the JDK and now is not anymore and it was renamed to Jakarta somehow.

Advertisement

Answer

The most straight forward and easiest way of properly including JAXB is to include the reference JAXB implementation and exclude any ZIP file dependencies since these result in Error occurred during initialization of boot layer [...] Module format not recognized when your library is included by another project itself.

JavaScript

In case the included dependencies should be further minimized jaxb-xjc and jaxb-jxc can be excluded as well.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement