IntelliJ: Error:java: error: release version 5 not supported

Problem: While creating a new maven project using IntelliJ IDEA with Java 11 started getting the following error:

Error:java: error: release version 5 not supported

After exploring the internet for a while I found what is causing this error.

Reason: Generally Maven sets the default Java version to 1.5. Hence you need to set the correct language level and release version in pom.xml.

Before searching for a solution you can check your current Java version at, File => Settings => Build, Execution, Deployment => Compiler => Java Compiler and change it if required.

IntelliJ_Java_compiler_version

Even after changing the java version, if it didn’t work, you can apply the following solutions.

Solution 1:

Set the source /target versions in pom.xml like below:

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

You will also need to include the maven-compiler-plugin if you haven’t already like:

plugins>
     <plugin>
	 <groupId>org.apache.maven.plugins</groupId>
	      <artifactId>maven-compiler-plugin</artifactId>
	      <version>3.6.0</version>
	      <configuration>
	        <source>1.11</source>
                <target>1.11</target>
	      </configuration>
	</plugin>
</plugins>

Solution 2: Specific to SPring boot, If you are using spring boot as a parent, you have to set the java version.

<properties>
   <java.version>11</java.version>
</properties>

This will automatically set the correct versions.

If The above-mentioned option didn’t work for you, you can move one step further by changing the “language level” in every module at, File => Project Structure => Modules

Here we discussed how we can change the Java compiler version in IntelliJ and solution to common error while creating a maven project using IntelliJ.

You are free to share if there are other ways to fix this error.

If you are new to Java you may find these articles helpful.

What happens when a Java object is created?

Java bitwise operators with example

Java Exception in detail with example

How to create Java Custom Exception?

Java try with resources statement

Java Generic, Generic with super and wildcard

Happy Learning !!