javaxmlxml-parsingjava-17xerces2-j

Modules jdk.xml.dom and xercesImpl export package org.w3c.dom.html to module io.cucumber.core.gherkin.messages'


Within one of my projects I used the following dependency:

<dependency>
  <groupId>xerces</groupId>
  <artifactId>xercesImpl</artifactId>
  <version>2.12.2</version>
  <exclusions>
    <exclusion>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
    </exclusion>
  </exclusions>
</dependency>

with the following module-info.java:

open module de.powerstat.fb.mini
 {
  exports de.powerstat.fb.mini;

  requires transitive java.xml;

  requires org.apache.logging.log4j;
  requires transitive de.powerstat.validation;

  requires transitive org.apache.httpcomponents.httpclient;
  requires org.apache.httpcomponents.httpcore;
  requires org.apache.commons.codec;

  requires com.github.spotbugs.annotations;
  requires org.junit.jupiter.api;
  requires org.junit.jupiter.params;
  requires org.junit.platform.launcher;
  requires org.junit.platform.suite.api;
 }

I got the following error message:

[INFO] --- surefire:3.5.0:test (default-test) @ miniapi ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Error occurred during initialization of boot layer
[INFO] Results:
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[WARNING] Corrupted channel by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file C:\MyProject\target\surefire-reports\2024-09-28T15-18-12_539-jvmRun1.dumpstream

Within the mentioned file there are the following messages:

Stream 'Error occurred during initialization of boot layer'.
Stream 'java.lang.module.ResolutionException: Modules jdk.xml.dom and xercesImpl export package org.w3c.dom.html to module io.cucumber.core.gherkin.messages'.

When looking through my dependencies I found:

jdk.xml.dom:

org.w3c.dom.css
org.w3c.dom.html
org.w3c.dom.stylesheets
org.w3c.dom.xpath

as well as:

xercesImpl-2.12.2.jar:

org.apache.*
org.w3c.dom.html

Which means that we have a split package here which is not allowed within the java module system.

Any idea for a workaround? Or maybe xerces is unusable with the java module system? Would Saxon be a replacement that works with the java module system? Or is there any other solution?


Solution

  • Thanks to the hint of Michael Kay it seems to be enough to remove the xerces dependency when using newer Java versions like 17:

    <!--
    <dependency>
      <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
      <version>2.12.2</version>
      <exclusions>
        <exclusion>
          <groupId>xml-apis</groupId>
          <artifactId>xml-apis</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    -->