Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idea Intellij: Error:java: error: release version 20 not supported, maven.compiler.target in pom.xml

I have a Idea Intellij project like this:

Test.java:

public class Test {
    public static void main(String[] args) {
        System.out.println("Test");
    }
}

pom.xml:

<?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>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
     
    <properties>
        <maven.compiler.target>20</maven.compiler.target>
        <maven.compiler.source>20</maven.compiler.source>
    </properties>
</project>

Idea Intellij

File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler

enter image description here

File -> Project Structure -> Project

enter image description here

File -> Project Structure -> Modules -> Sources

enter image description here

File -> Project Structure -> Modules -> Dependencies

enter image description here

When trying to run Test.java I get an error:

Error:java: error: release version 20 not supported

enter image description here

I use Ubuntu. When I type java --version in the terminal, I get:

openjdk 20 2023-03-21
OpenJDK Runtime Environment (build 20+36-2344)
OpenJDK 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)

I'm not sure how I can make Intellij use Java 20

When I use

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

the code runs fine. However I want a newer Java to be used, so that features like enhanced switch blocks:

switch (value)  {
 case 1 -> {}
}

are available

like image 746
parsecer Avatar asked Feb 24 '26 14:02

parsecer


2 Answers

You don't need to have Java 20 to use the enhanced switch blocks java 17 has it too. And you are building it in java 11, and compiling in java 20, which is the reason you are getting that error.

Generaly you need to add java 20 to your project in the screenshot file -> Project Structure -> project to use the libraries of java 20 that are compilable in java 20.

I hope that makes sense.

like image 117
Bladimir Jimenez Avatar answered Feb 27 '26 03:02

Bladimir Jimenez


I would recommend using 15 above, i personally use 17version by amazon correto and that switch feature is available. its up to what new java features you want to use.

however if you want to use the 20 version you had to set the sdk/jdk,language level to 20

like this:

https://i.sstatic.net/SBena.png

https://i.sstatic.net/TbyJh.png

https://i.sstatic.net/BAAQJ.png

https://i.sstatic.net/4tJmI.png

you might be missing those points.

like image 38
Saco MongoDB Avatar answered Feb 27 '26 03:02

Saco MongoDB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!