In a previous post, we talked about how to build Spring Boot Maven projects using Java 9 and Docker. Now we are going to do the same thing for Gradle projects. We'll use the offical Gradle Docker image with tag 4.0.1-jdk9. The sample project is also created using Spring Initializr.

It's good to know that the Java 9 version in this Docker image has upgraded to buid 177.

Before we run the Gradle build, we need to update the sourceCompatibility to 9. Java 9 has updated the version strings schema. The prefix 1 has been removed. The version strings of Java 9 start from 9.

sourceCompatibility = 9

We use following command to run gradle build.

$ docker run --rm -v "$PWD":/project -w /project \
  --name gradle gradle:4.0.1-jdk9 \
  gradle build

To fix potential issues with Gradle, it's better to set the flag --illegal-access=permit. We can add following configuration to the file

org.gradle.jvmargs=-XX:+IgnoreUnrecognizedVMOptions --illegal-access=permit