You didn't say what IDE you are using, but I am guessing IntelliJ. You also didn't show the Gradle configuration in IntelliJ, so I am assuming you are going by the default settings and that its a relatively new version.
You can chose between having IntelliJ compile your source code, or let Gradle do it. The default is Gradle, so it doesn't matter what how you configure the IntelliJ compiler as it isn't used.
If you don't fork the Gradle compilation, it will use the same JDK for compilation as for running Gradle. In IntelliJ, this is configured in the Gradle JVM
setting under Build Tools -> Gradle
(or JAVA_HOME
if you are running it from the CLI).
Now back to your question. The reason you can't use the var
keyword is exactly because you have configured it to target Java 8. That means the source also have to be compatible with Java 8. If you think about it, newer language features usually require newer versions of the byte code. So if you need your final binary to be compatible with Java 8, you need the source to be compatible with Java 8 as well.
You can still use Java 13 to compile to Java 8 byte code (as long as you program against a Java 8 API and syntax). But instead of just the "target" version, you should use the --release
flag as this will also configure the bootclasspath
correctly, which I am guessing you didn't do (this ensures that you use the correct API). For instance:
compileJava {
options.compilerArgs.addAll(['--release', '8'])
}