Different Maven and Gradle execution of Java 9+ Modular Junit 5 tests

While Maven just works, with Gradle you have to set various module command line arguments

Need to add this boilerplate code for compileTestJava and test tasks:

compileTestJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'org.junit.jupiter.api',
            '--add-reads', "$moduleName=org.junit.jupiter.api",
           '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
        ]
        classpath = files()
    }
}

test {
    useJUnitPlatform()

    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath
        ]
    }
}
2 Likes