Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 511
Leem Avatar asked Feb 25 '20 10:02

Leem


People also ask

Does IntelliJ use JDK or JRE?

Java Development Kit (JDK) To develop applications in IntelliJ IDEA, you need a Java SDK (JDK). A JDK is a software package that contains libraries, tools for developing and testing Java applications (development tools), and tools for running applications on the Java platform (Java Runtime Environment — JRE).

How do I know what version of JRE I have?

Click "Installation Details", choose the Configuration tab, and scroll down to the "java. home" entry. The value is the path name to the JVM used. JDK's include JRE's.

How to change the target JRE version for Gradle in IntelliJ?

The target JRE version for Gradle can be configured from within Intellij via the Gradle JVM setting at Preferences (cmd + ,) > Build, Execution, Deployment > Gradle: The project JDK version can be configured from the Project SDK setting in Project Structure (cmd + ;): (Screenshots taken from IntelliJ IDEA 2020.1.4) Show activity on this post.

How do I change the JDK version IntelliJ runs under?

Harirao3: The JDK version that IntelliJ runs under is entirely unrelated to the JDK your project runs under. To change your project JDK go to View --> Open Module Settings --> Project Settings --> Project --> Project SDK

How do I run IntelliJ IDEA with another Java Runtime?

If you need to run IntelliJ IDEA using another Java runtime, refer to Change the boot Java runtime of the IDE for instructions. For more information, refer to the Java 16 and IntelliJ IDEA blog post.

Why is JetBrains runtime not updating with IntelliJ IDEA?

When using a non-default Java runtime for IntelliJ IDEA, it will not update with the IDE and may not be compatible with the new version. Reset back to the default runtime when updating IntelliJ IDEA to get the latest compatible version of JetBrains Runtime.


2 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)

like image 99
rusheb Avatar answered Sep 20 '22 09:09

rusheb


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:

  • https://docs.gradle.org/current/userguide/java_plugin.html#sec:java-extension
  • https://docs.gradle.org/current/javadoc/org/gradle/api/JavaVersion.html

Maven

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

Docs:

  • http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

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.

like image 42
Markiian Benovskyi Avatar answered Sep 20 '22 09:09

Markiian Benovskyi