GeezerVison is showing github.com — Release using the new jakarta namespace (jakarta.xml.bind 3.x) · Issue #227 · xmlunit/xmlunit
Release using the new jakarta namespace (jakarta.xml.bind 3.x) #227DescriptionCurrently there is a dependency to the Jakarta XML bind version 2.33, which is still using the old "javax." namespace. For projects starting to migrate fully to the new "jakarta." namespace, this pulls in unwanted dependencies.
XML unit should provide a release that uses version 3.x of jakarta.xml.bind" that has the package namespace changed to jakarta.xml.bind.* (Currently version 3.0.1).
<properties>
<!-- Jakarta XML Binding version -->
<jakarta.xml.bind.version>2.3.3</jakarta.xml.bind.version>
</properties>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jakarta.xml.bind.version}</version>
</dependency>Activitybodewig commented on Aug 29, 2021 The question is how to do that without stopping support for all projects that have not migrated, yet. michael-schnell commented on Aug 29, 2021 I created a separate branch to support both variants for some time. The Hibernate project created a separate Maven artifact named "-jakarta" for the new namespace. So you have "org.hibernate:hibernate-core-jakarta" inlcuding "jakarta." and "org.hibernate:hibernate-core" without it. Both have the same version and content. Only difference is the "jakarta." package. bodewig commented on Aug 29, 2021 yes, I was thinking about adding a new module as well, but that will (a) not remove the unwanted dependency and (b) not magically be used by Input.from. I'd prefer a solution that doesn't force existing setups to change anything when they upgrade but don't see one that doesn't still pull in the "unwanted" JAXB dependency.
I could create two JAXB modules and remove JAXB support from core (and maybe make Input use reflection or ServiceLoader to see whether either one is available), but that will force existing projects using JAXB to add a new dependency on the new "classic JAXB" module.
Duplicating the whole of core (which is how I understand yur suggestion) would also mean I'd have to duplicate the other modules as they depend on core (with and without jakarta suffix). Of course this is doable but it doesn't feel right at all. michael-schnell commented on Aug 29, 2021 Yes, unfortunately there isn't really a good solution for this. I would go for a branch that has exactly the same code except the imports and pom adjustments. It's not that complicated to keep the code changes aligned. You could use the Eclipse Transformer utility to do it mostly automated for the first time. bodewig commented on Aug 30, 2021 My bigger problem is going from seven artifacts per release to fourteen (or thirteen if I somehow manage to use the same parent for both sets). In particular when each pair of artifacts is completely identical for users who do not use JAXB at all - which I wager to be the majority of users.
TBH, thinking about how many words I'd need to tell people which artifacts to use - and time I need to spend in order to address "I'm using xmlunit-core-jakarta and my dependency uses xmlunit-core, how am I going to resolve this" issues it will probably be easier to remove JAXB from core and make it a 3.0 release. phbenisc commented on Aug 30, 2021 Indeed a tricky situation.
I also think removing JAXB from the core would make sense. So it will only break on projects with JAXB and these are the people benefitting from the maintenance on their JAXB version. Other projects without JAXB do not get polluted with an additional dependency.
The disadvantage would be that the JAXB functionality from Input.fromJaxb and Input.from would go out the window.
Maybe (!) a possible way to counter that would be a simple plugin mechanism in the Input.class with the ServiceLoader.class. I am however unsure how the mechanism works with the JAVA 9 module system... 😅
That still means that all JAXB users would need to add an dependency. bodewig commented on Aug 30, 2021 ServiceLoader is the way I imagine to go - and it is supposed to work with Java modules as well as OSGi. It looks as if this requires a module descriptor and some OSGi magic inside of the manifest to make things work as smooth as possible.
Yes, people will need to add a new dependency, which is why I believe this will require a new major release. And if I do that, I should probably think about other things I'd like to do differently but am forced to keep for backwards compatibility reasons. Right now I haven't got any specifics in mind but will look through the issues - in particular the "question" labelled ones. phbenisc commented on Oct 2, 2021 The thing with ServiceLoader is that one has to think about, what should happen when more than one implementation is found.
What should happen in that case?
For me there are two choices:
- We only allow one implementing service and raise an
Exception if another one is found
- We find a way to support more than on implementation
- We could simple try every implementation (and catch exception - not a great practice)
- We could let the implementing interface decide, whether it can handle the object by showing it the object beforehand. Still in that case the JAXB implementations (! both potentially) would grab anything (currently it simply tries)
- We could let the interface return supported classes. Very similar to the current
instanceof chain in the Input class. If more than one implementation is found, we try until all possibilities are exhausted or we raise an exception (which would happen if both JAXB implementation are on the class path and we return Object, for the JAXB implementations)
I think none of my proposals are perfect. Limiting the implementation to one, does limit the future extensibility.
While the other ones basically try very hard or to foresee the future 😅.
I have this October some time to spare. If you want I can get things get started or do another ticket.
Edit: made my Denglish more tolerable.
Edit2: future use cases i can think of:
bodewig commented on Oct 3, 2021 TBH I had just been thinking about creating an interface to abstract away JAXB implementations, but adding some sort of input abstraction might be a useful addition, you are right. We'd likely need so sort of ordering as JAXB would trump all others by accepting everything. I guess it would be easier to ask an implementation what they can support rather than providing them with the object and let them try.
A "what kind of classes can you support" method could be used for ordering implicitly (pick the most specific class) but may still lead to ambiguities. An HTML or JSON accepting implementation would likely say it can deal with InputStreams, a Jackson implementation will probably also work on Object. While we could try all implementations and catch exceptions for general Objects it doesn't work for resources that get exhausted - like an InputStream you cannot rewind. This is a bit tricky and we'll need to think this through more, but I agree the idea is interesting.
As for your spare time, I will welcome you trying out ideas and sharing the results in any way you see fit. Please keep in mind that my "open source time" is a bit more limited than yours seems to be for the next weeks to come so please bear with me. :-) bodewig commented on Jan 16, 2022 I have merged #247 right now and will publish 2.9.0-SNAPSHOT artifacts. In https://github.com/xmlunit/user-guide/wiki/JAXB I've described how I believe XMLUnit should work with JAXB 3.x.
@Joerg-Schoemer @michael-schnell it would be good if you could try the snapshots to see whether it actually works as advertised.
@phbenisc I really like the more generic input builder idea but wanted to shoot for a simpler and quicker solution. Also I'm afraid this is going to require API changes to become useful, so this may be better suited for a XMLUnit 3.x release that is willing to break things. I'll start collecting ideas for 3.x inside the developer wiki sometime the coming week - but must admit progress may be slower than one would hope for. sratz commented on Nov 20, 2024 Even with #247 merged, the OSGI metadata still pulls in Import-Package: javax.xml.bind....:
https://repo1.maven.org/maven2/org/xmlunit/xmlunit-core/2.10.0/xmlunit-core-2.10.0.jar
...
Import-Package: javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.
util,javax.xml.namespace,javax.xml.parsers,javax.xml.transform,javax.xm
l.transform.dom,javax.xml.transform.sax,javax.xml.transform.stream,java
x.xml.validation,javax.xml.xpath,org.w3c.dom,org.xml.sax,org.xml.sax.he
lpers
...
I think these should be made ;resolution=optional:
|
<Import-Package>*</Import-Package> |
thmuch commented on Jul 23, 2025 @sratz FYI: XMLUnit 2.10.3 fixed the OSGi metadata problem for us. Reacted by Sebastian Ratz
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|