0

I run the following command under the root path of my java spring boot (grade) project on my Terminal:

./gradlew clean check

But I get error message:

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

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

How to get rid of this error?

Leem
  • 17,220
  • 36
  • 109
  • 159

3 Answers3

2

Old question but I looked for the same just now.

Gradle has a default JVM set in your %userprofile%/.gradle/gradle.properties. This is in the folder "C:\Users\j.gradle\gradle.properties" for me:

That's where you should also put your newer JVM to make sure gradle can compile newer projects. Looks like this now:

org.gradle.java.home=C:/Program Files/AdoptOpenJDK/jdk-11.0.7.10-hotspot

See also this thread where I posted the same answer: https://stackoverflow.com/a/62564011/2807735

judos
  • 445
  • 4
  • 14
1

You are trying to compile classes to Java 12, but you are using a Java 8 JDK.

If you type in java -version in console, you should see Java 8. You need to install Java 12 or higher and put it on your PATH OR change your target to Java 8

Tom Cools
  • 1,098
  • 8
  • 23
0

As a result of another SO fix I had these sections in different parts build.gradle (app):

compileOptions {
    sourceCompatibility 1_8
    targetCompatibility 1_8
}

compileOptions {
    sourceCompatibility 1_7
    targetCompatibility 1_7
}

I removed second and the problem was fixed.

Stephen Hosking
  • 1,405
  • 16
  • 34