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:
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)
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).
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.
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.
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
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.
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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With