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
File -> Project Structure -> Project
File -> Project Structure -> Modules -> Sources
File -> Project Structure -> Modules -> Dependencies
When trying to run Test.java
I get an error:
Error:java: error: release version 20 not supported
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
maven.compiler.release
to ensure code is compatible when it is being built with a newer JDK. – Toombs