This is a setting in IntelliJ IDEA ($JAVA_HOME
and language level were set to 1.8):
File
> Settings
> Build, Execution, Deployment
> Gradle
> Gradle JVM
Select eg. Project SDK (corretto-1.8)
(or any other compatible version).
Then delete the build
directory and restart the IDE.