In my project, there are 2 libraries, each of which depend on the XML parsing class java.xml.parsers.DocumentBuilderFactory. Each of these libraries reference the file from different jar (one gets it from a jar called xmlParserAPIs while another gets it from xml-apis-1.0.b2.jar). Unfortunately there are different versions of the class in each of these files so I am seeing runtime errors, depending on the order they are loaded. Both of these xml jars are transitive dependencies of 3rd party libraries. Is there a good way to handle this conflict?
edit: I’m not sure if it makes a difference on how to handle the problem but this only happens in testing because one of the dependencies is in the test scope.
thanks,
jeff
In theory,
xml-apis.jarandxmlParserAPIs.jar(from xerces2-j) are the same JARs but with different names,xmlParserAPIs.jarbeing deprecated for years (see this message and this one).If your dependencies relies on different and incompatible versions of
xml-apis.jar, I would say that these dependencies are mutually exclusive, in other words incompatible, at least for the versions you’re using. The only solution would be to find versions with a converging dependency.In case they could use compatible versions, use a dependency exclusion for
xmlParserAPIs.jarto usexml-api.jaronly.No, this just explains why you don’t get the problem at runtime (because the
testscoped is not on the classpath then and, obviously, doesn’t conflict).