Prevent test errors in 'mvn site' goal with ROME dependency and cobertura-maven-plugin
-
02-01-2020 - |
Question
In a Maven based project some of the JUnit tests fail, but only during a Maven site build. When executing
mvn clean package
all tests pass. But when executing:
mvn clean site
some of the tests generate the message:
Could not initialize class org.jdom2.input.sax.XMLReaders
These errors occur in a class that uses ROME to parse RSS data. For this the project has a dependency on ROME (com.rometools:rome:1.5.0), which itself has a dependency on JDOM 2.0.2.
The errors did not happen when the ROME dependency was not yet included in the project.
The Maven site configuration includes the cobertura-maven-plugin. This also has a dependency on JDOM, through Jaxen: jaxen:jaxen:1.0 -> jdom:jdom:1.0
I think that while executing the site goal the JDOM 1.0 version is used by the class under test, causing the errors in the ROME library because it uses the incorrect JDOM version.
I don't know how to configure the project to use JDOM 1.0 only in the Cobertura plugin. Does anyone know a way to do that and make the tests run successful during the site goal?
Solution
The problem was solved by setting a system value during program startup:
System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
Source: JDOM2: This parser does not support specification "null" version "null"