How to fix Intellij – Maven projects – Java release Version is not supported and Java language level errors

In this tutorial, learn how to fix Intellij – Maven projects – Java release Version is not supported and Java language level errors.

We recently built a new Maven project in Intellij Idea 2019 and when we tried to compile it, we received the error shown below.

The following was the error message: Error:java: error: release version 5 not supported. There could be a variety of other concerns, such as the inability to use java:string in switches, the lack of support for the java:diamond operator in -source 1.5, and so on.

See more: How to Install Google Chrome on Ubuntu Linux

What is the issue

This occurs because Maven defaults to Java 1.5, which is a fairly outdated version. On the Maven webpage, it says:

“Apache Maven Compiler Plugin
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.”

To resolve the problem, we must specify the Java version to be utilized.

See more: How to Install IntelliJ IDEA on Windows 10

How To Fix Java release version is not supported error in IntelliJ IDEA Maven project

What we need to do, according to the Maven website, is add the following lines of code to the pom.xml file. I chose Java version 16 as the source and target, but you should use the version of Java that you are running.

<build>
                <plugins>
                        <plugin>
                                 <groupId>org.apache.maven.plugins</groupId>
                                 <artifactId>maven-compiler-plugin</artifactId>
                                 <version>3.8.1</version>
                                 <configuration>
                                          <source>11</source>
                                          <target>11</target>
                                 </configuration>
                          </plugin>
                 </plugins>
         </build>

This is what your pom.xml file should look like:

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″
                 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
                 xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
       <modelVersion>4.0.0</modelVersion>

       <groupId>your project group ID</groupId>
       <artifactId>your project artifact ID</artifactId>
       <version>1.0-SNAPSHOT</version>
       <build>
                <plugins>
                        <plugin>
                                 <groupId>org.apache.maven.plugins</groupId>
                                 <artifactId>maven-compiler-plugin</artifactId>
                                 <version>3.8.1</version>
                                 <configuration>
                                           <source>11</source>
                                           <target>11</target>
                                 </configuration>
                        </plugin>
                </plugins>
         </build>
</project>

You can find out the version of Java you’re running in Intellij by heading to File -> Project Structure and then Project settings, Project, as shown in the screenshot below.

If you’ve any queries, check this video:

That’s all there is to it; have fun coding.

Loading Facebook Comments ...