Unsupported Java. Your build is currently configured to use Java 21 and Gradle 8.5 using idea in a javaFx project

Hello, sorry for the long title !
I am a java gradle and idea newbie.

I’d like to build a JavaFX project, I’ve selected Gradle for project build and I get the following error message building the project ( I use idea Community 2023.2.2 on WSL2 with ubuntu 22.04 ) :

Unsupported class file major version 65

Further details are given in a side window:

Unsupported Java.
Your build is currently configured to use Java 21 and Gradle 8.5.

Possible solution:

  • Use Java 20 as Gradle JVM: Open Gradle settings
  • Open Gradle wrapper settings, change distributionUrl property to use compatible Gradle version and reload the project

I don’t want to step back towards Java 20 or older version as I would like to stick to java 21 which is a LTS version.

According to some Gradle manual, Gradle version 8.5 should be ok for java21 Compatibility Matrix

Here is my Gradle-wrapper-properties file:


In Settings >Build, Execution, Deployment > Build Tools > Gradle

in Gradle Projects section:

Build and Run__________________________________

Build and run using: Gradle(Default)

Run tests using: Gradle( Default)

Gradle _______________________________________

Distribution Wrapper

Gradle JVM openjdk21 Oracle OpenJDK

Does someone knows how to fix that ?
Thanks very much for your help !

I found my error running gradlew build from root project directory : Execution failed for task ‘:compileJava’.

error: invalid source release: 21

I had only installed java 21 library but the java executable was still version 19