Intellij, target JRE vesion doesn't match project jdk version

Viewed 10254

I am using Intellij Community version 2019.3 on my MacBook. I have a simple springboot (java) project. Whenever I run my unit test I get the following warning:

enter image description here

Where should I check on Intellij to get rid of this error? (I heard on internet "Project Settings", but I can't find where this option is)

3 Answers

The target JRE version for Gradle can be configured from within Intellij via the Gradle JVM setting at Preferences (cmd + ,) > Build, Execution, Deployment > Gradle:

Gradle JVM Setting

The project JDK version can be configured from the Project SDK setting in Project Structure (cmd + ;):

Project SDK setting

(Screenshots taken from IntelliJ IDEA 2020.1.4)

This is because you are building for target version of Java 1.8

Depending what you are using, Maven or Gradle, you set the target version of java with:

Gradle

  sourceCompatibility = '1.8'
  targetCompatibility = '1.8'

Docs:

Maven

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

Docs:

You can change this version to 12 or JavaVersion.VERSION_12 to use your build JDK, but then you would lose the compatibility and won't be able to run the application jar with Java 1.8.

You can also change the build SDK version, on macOS press command + ; and go to Project Settings -> Project and change the Project SDK to the one you want to build it with.

Intellij + Gradle also refers to the Gradle JVM setup within Intellij.

Ensure to change that as shown below: enter image description here

Related