Gradle 5 & Java 11 build error: Why does Gradle think I'm using Java 10?

heez :

I'm unable to build my project using Java 11 and Gradle 5. I receive the following error trying to build:

$ gradle clean build
> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 10 (1.10)'.

Why does Gradle think I'm using JDK 10? My $JAVA_HOME is set to /usr/lib/jvm/java-1.11.0-openjdk-amd64/, which is the Linux OpenJDK build for Java 11 (found here https://jdk.java.net/11/). I'm using Gradle 5, but this error also occurred using 4.10.2.

Below are the relevant parts of my build.gradle:

apply plugin: 'java'
sourceCompatibility = 11

I've also tried using 1.11 for source compatibility but this also fails with the same error.

heez :

The issue was unique to Ubuntu 18. The "JDK11" that is in apt is actually JDK10 with backported JDK11 security updates. That's fairly confusing, so there is an open bug report with Ubuntu. See also this post on the AskUbuntu stack exchange.

To resolve the issue you have to manually set your system to use an actual JDK11. I did something similar to this guide to fix it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77940&siteId=1