gradlejavafxjava-19

Excluding a duplicate package in gradle


I have a gradle build that uses javafx, log4j from maven and jOpenDocument-1.5 from a jar in a local flatDir (folder). When I build under JDK19 I get the following errors

error: the unnamed module reads package org.w3c.dom from both jOpenDocument and java.xml
error: module javafx.graphicsEmpty reads package org.w3c.dom from both jOpenDocument and java.xml
error: module javafx.baseEmpty reads package org.w3c.dom from both jOpenDocument and java.xml
error: module org.apache.logging.log4j.core reads package org.w3c.dom from both jOpenDocument and java.xml
error: module javafx.controlsEmpty reads package org.w3c.dom from both jOpenDocument and java.xml
error: module jOpenDocument reads package org.w3c.dom from both java.xml and jOpenDocument

Gradle provides a collection of mechanisms that should allow me to exclude the org.w3c.com package from the build. Gradle wants me to specify a "group" and/or a "module", but the error messages specify a "java package" but not the group and module names.

I would like the build to use the org.w3c.dom package from java.xml and exclude the org.w3c.dom package from jOpenDocument. I chose the java.xml variant of the package because the jOpenDocument variant has just org.w3c.dom.UserDataHandler.class so removing it should make it less likely to have side-effects in other dependencies.

The Gradle build scans did not go down to a package level analysis. It doesn't really tell me anything I can act on. That may be more my ignorance.

The following snippet from my build.gradle file is what I have now. It doesn't work probably because org.w3c.dom is a package and not a gradle/maven module.

dependencies {
    testImplementation 'org.testng:testng:7.4.0'

    implementation 'org.apache.logging.log4j:log4j-api:2.14.1'
    implementation 'org.apache.logging.log4j:log4j-core:2.14.1'

    implementation ('libs:jOpenDocument-1.5') {
        exclude module: 'org.w3c.dom'
    }

}

  1. How should I amend the build.gradle file to resolve this duplicate dependency?
  2. What is a Gradle build dependency module if its not a package?

Solution

  • I removed the /org/w3c/dom/UserDataHandler.class file and its parent folder at org/w3c/dom from the JAR file (JAR files being ZIP files) manually. (Thank you @Slaw)

    ... job done. Note that I have yet to test whether there are any functional side-effects.

    The latest version (jOpenDocument-1.5.jar) is not on Maven. So, I could edit the JAR manually in my local flat directory repository. I used ark to do the deleting. That may change - I see a request has been made. I would prefer to use officially published versions from Maven because they more maintainable over the long term. So, towards the end of development, I will have a go at enhancing my build.gradle file to perform this edit programmatically, most likely using jar commands, as suggested by @jewelsea,

    Two closing thoughts if I may.

    1. I am trying out Test Driven Development for the first time. TDD probably brought this problem forward, which I count as a good thing. The benefit being I do not have any rework to do; so +1 for TDD.
    2. With deleting a class from a jar being so straightforward, I cannot help but feel there should be a conventional way to specify excluding a specific class or package in the build configuration. If it exists, it will be documented somewhere in the Gradle or Gradle plug-in manuals; and that will require an archaeological dig, time and a spare brain cell.