Build Spring Boot Gradle projects using Java 9 and Docker

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.

1
sourceCompatibility = 9

We use following command to run gradle build.

1
2
3
$ 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 gradle.properties.

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

Exploring Java 9

Check out my book Exploring Java 9 for new features in Java 9.

Comments