Java modules ResolutionException happening only when unit testing with JUnit5 and IntelliJ

39 views Asked by At

I have a desktop JavaFX application using Java 9 modules system, Gradle and IntelliJ. The application builds and runs perfectly with Gradle run task. I am using it without any issue.

Now I am introducing some very simple unit testing with JUnit5, but the test cannot run due to the following module resolution exception

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules xercesImpl and jdk.xml.dom export package org.w3c.dom.html to module commons.logging

My build.gradle looks like:

plugins {
    id 'java'
    id 'org.javamodularity.moduleplugin' version '1.8.12'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation project(':api')
    implementation 'org.xerial:sqlite-jdbc:3.41.2.2'
    implementation 'org.odftoolkit:odfdom-java:0.12.0'
    implementation 'com.hummeling:if97:2.0.0'
    testImplementation(platform('org.junit:junit-bom:5.10.1'))
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

tasks.named('test', Test) {
    useJUnitPlatform()
}

Why is this conflict happening only in the testing run? How am I supposed to resolve this type of issue? Many thanks!

1

There are 1 answers

0
CT95 On

Recalling and older post related to Odfdom problems, I found that it was sufficient to exclude xercesImpl module for the test run. With the following dependencies configuration the unit test now works:

dependencies {
    implementation project(':api')

    implementation 'org.xerial:sqlite-jdbc:3.41.2.2'
    implementation 'org.odftoolkit:odfdom-java:0.12.0'
    implementation 'com.hummeling:if97:2.0.0'

    testImplementation(platform('org.junit:junit-bom:5.10.1'))
    testImplementation 'org.junit.jupiter:junit-jupiter'

    // Removes a conflict that prevents unit tests execution
    configurations {
        testRuntimeOnly.exclude group: 'xerces', module: 'xercesImpl'
    }

}