Search code examples
javaspring-bootintellij-idea

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


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)


Solution

  • 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.