JUnit 5, Java 9 and Gradle: How to get through --add modules?

I want to upgrade from Java 8 to Java 9. When I run my tests, I get CNFE in relation to javax.xml.bind.JAXBContext. Therefore, "-add-modules java.xml.bind" seems to be required. I tried to extend the GRADLE_OPTS ENV variable, but the error remains. Any hints are welcome.

+4
source share
2 answers

According to Alan Bateman, I added the following lines to build.gradle, to gradle bootRunalso work:

runtime('org.glassfish.jaxb:jaxb-runtime:2.3.0', 'javax.activation:activation:1.1.1')
+2
source

You can follow the five basic steps during migration, as indicated in gradle -building java9 modules , which are: -

java- Java 9, , .

  • module-info.java, .

  • compileJava, .

  • compileTestJava, .

  • test .

  • () Automatic-Module-Name .


,

compileTestJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath, 
            '--add-modules', 'org.junit.jupiter.api',  // junit5 automatic module specific
            '--add-modules', 'java.xml.bind' // jaxb specific
            '--add-reads', "$moduleName=org.junit.jupiter.api", // allow junit to read your module
            '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath, // add test source files to your module

        ]
        classpath = files()
    }
}

test

test {
    inputs.property("moduleName", moduleName)
    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath, 
            '--add-modules', 'ALL-MODULE-PATH', // to resolve all module in the module path to be accessed by gradle test runner
            '--add-reads', "$moduleName=org.junit.jupiter.api", 
            '--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath, 
        ]
        classpath = files()
    }
}

. , , .

+4

Source: https://habr.com/ru/post/1688340/


All Articles