Gradle 5.3.1 / jdk 11 yields new 'module not found' error

ok, so I need to run on jdk 8 still :frowning: and would like to get my build working in jdk 11 (it works on 8, 9 and 10). I ran into this error

Task :http:http2-parser:compileTestJava FAILED
error: module not found: java.xml.bind

Now, I ran into something similar back in jdk 9 so I simply added this to gradle and problem was ‘averted’ for the time being…

compileTestJava {
options.compilerArgs += ["–add-modules", “java.xml.bind”]

Of course, in jdk11, this now breaks since I think this is no longer in the jdk and must be retrieved from maven?

Is there a way to say jdk11+ bring in a maven artifact and jdk 11- use those compilerArgs?


I’ve successfully built projects on Windows with OpenJDK 11 and Gradle 5.2.1. I’ve built some of the same projects on Linux with OpenJDK 12 and Gradle 5.2.1 and 5.3.1. One of those projects, I even compiled on Linux with 12 to a source and targetCompatibility of 1.7. And yet another one from 12 to 11 source and targetCompatibility.

In all cases, Gradle 5.2.1 and 5.3.1 just worked without me having to explicitly set anything in the way of JVM arguments.

I don’t have a solution to suggest to you. But could it be something specific to your environment?

The most direct way is basically to have the dependency and the compiler args behind a conditional, something like:

dependencies {
    if (useExternalXmlBind) {
        // Add required external dependency

and similarly for the compiler args.

And of course the way you compute the value of the flag depends on how your build is setup to execute with different Java versions.