Smatt14
Smatt14

Reputation: 791

java: error: release version 17 not supported

I recently updated to Intellij 2021.1. However, whenever I try to run my program, I get:

java: error: release version 17 not supported

I have tried snooping around for other answers, and have found none. It appears my SDK is version 16, if that helps.

Upvotes: 77

Views: 247477

Answers (29)

Soundararajan
Soundararajan

Reputation: 2194

In my case, the pom file is right, the java version, source, target version are set correctly, but I was compiling from command line and the default java interpreter is set to JAVA 1.8. Updating it to JAVA 17 made it work.

Upvotes: 0

Chris Sprague
Chris Sprague

Reputation: 3594

Here are the THREE locations I've seen:

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 0

Mahesh Jamdade
Mahesh Jamdade

Reputation: 20369

Running Spring application from terminal

Note that this is not necessary if your are using IntelliJ, Only if you are running the spring boot application from terminal otherwise skip to step 2

Firstly check what version of Java is your system using by running java --version In my case my system had java 16 path configured

mahesh@Maheshs-MacBook-Air-M1-3 expenses-backend % java --version
openjdk 16.0.1 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
mahesh@Maheshs-MacBook-Air-M1-3 expenses-backend % 

You can also check the exact path by running echo $JAVA_HOME

Using Step 2 download or select the JDK of your choice, Once you follow the below steps to setup your JDK of your choice update the JAVA_HOME path in ~/.zshrc or ~/.bashrc based on the shell you are using bash or zsh

and finally update the java.version in pom.xml

If you are using IntelliJ

Now, Check in your pom.xml What version of java does your project need my project has version 17 specified while in pom.xml, So I changed that to 20

<java.version>20</java.version>

Then in your Intellij IDE go to File -> Project structure -> SDKs You should see the list of Sdks on the left, if you don't see them click on the + icon to add a new JDK

Intellij should help you detect available JDKs in your environment, if your system already has the JDK that your are looking for (e.g JDK 20 in this case) then choose it.

enter image description here

If not you can download the required JDK from the vendor of your choice

enter image description here

Finally after you apply and save click on File -> Reload from disk to reindex the selected JDK

Upvotes: 0

2024-07-29: The real problem in using IntelliJ, even the newest one, 2024.1.1 Ultimate Edition, is there are too many places where a Java version has to be specified. If any of them are wrong or inconsistent, any number of errors can occurs.

Bottom line: JetBrains needs to change IntelliJ to have "one version of the truth" (one single place) where you specify which version of Java you want to use. Until that happens, posts like the ones in this thread will continue to cause the confusion and hair-pulling among developers trying to tell IntelliJ what version of Java is desired for a given project.

Upvotes: 0

Manjunatha D
Manjunatha D

Reputation: 1

check below three properties in the pom.xml Versions should match to the available java SDK version.

 <maven.compiler.source>17</maven.compiler.source>
 <maven.compiler.target>17</maven.compiler.target>
 <java.version>17</java.version>

Upvotes: 0

shivendra deep
shivendra deep

Reputation: 21

just go to environment variables and change tha path to jdk 17 thats it

Upvotes: 0

alperc
alperc

Reputation: 383

Upgrading from Java 8/11 to Java 17:

<properties>
  <maven.compiler.release>17</maven.compiler.release>
  <jdk.version>1.17</jdk.version>
  ....
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.11.0</version>
    <configuration>
       <source>${jdk.version}</source>
       <target>${jdk.version}</target>
    </configuration>
</plugin>

Upvotes: 0

nuclear_bean
nuclear_bean

Reputation: 333

For those using maven-compiler-plugin, adding version in plugin config solves the problem

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

Upvotes: 1

Shirish Bari
Shirish Bari

Reputation: 2722

I setup the SDK and Compiler version correctly still I had the same issue.

Finally, after changing the gradle jvm to use java-17, issue got resolved.

I followed below steps :

  • Press Ctrl+Alt+S(letter S) to open settings
  • Go to Build, Execution and Deployment
  • Then go to Build tool
  • select gradle
  • Change the gradle-jvm to java-17

please refer below image:

enter image description here

Upvotes: 0

Jack Vicky
Jack Vicky

Reputation: 301

I have tried all the steps like changing the "Target bytecode version" and "Project bytecode version" and "project language level" but none got worked out. finally I fixed it by upgrading the JDK version from 1.8 to the latest version jdk-20.

Note: Don't forget to change the JAVA_HOME path post upgrading the JDK :)

enter image description here

Upvotes: 2

Tejesh Reddy
Tejesh Reddy

Reputation: 11

The solution that worked for me was to download Java version 17. You can do this by navigating to File - Project Structure - SDKs and clicking the + button under the Classpath Download button

Upvotes: 1

Kehinde Onadipe
Kehinde Onadipe

Reputation: 121

There are two actions to take:

  1. Go to File -> Project structure -> Modules and changed the Language level to 17
  2. Go to IntelliJ IDEA -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler. Change your module's Target bytecode version version to 17.

Upvotes: 5

Kalu Ngozi
Kalu Ngozi

Reputation: 21

This worked for me. I went to Project Settings, clicked on Build, Execution, and Deployment, clicked on Java, clicked on Java Compiler, then changed the Java version (Target bytecode version) to 11.

Upvotes: 2

cyril
cyril

Reputation: 1017

for me i spend really lot of time all was configured correctly, but strangely, the pom.xml was ignored, so right click on pom file => maven => unignore project (on all projects and module)

enter image description here

Upvotes: 0

Ashish
Ashish

Reputation: 1917

In my case, I had to change the JAVA_HOME and the Path system environment variable to point to Java 17 (I used Amazon Corretto) as well in addition to updating Language Level and SDK for Project. My modules used inheritedJdk from Project itself. Java Compiler version was also 17.

Upvotes: 6

Mounir bkr
Mounir bkr

Reputation: 1665

  1. file => setting => Build,Execution,Deployment => Java Compiler
  2. change Target bytcode version to your current version of project.enter image description here

Upvotes: 10

Wojciech Fornal
Wojciech Fornal

Reputation: 1563

There is one more place worth checking -> Java Compiler settings

IntelliJ IDEA Settings

Upvotes: 63

twu
twu

Reputation: 31

For me these had to match...

  1. File | Project Structure | Project | Project SDK

  2. File | Project Structure | Modules | Language level

  3. IntelliJ Idea | Preferences | Build, Exec... | Build Tools | Maven | Importing | JDK for importer

  4. system.properties (file) java.runtime.version=

  5. pom.xml - <java.version>

Upvotes: 3

koppor
koppor

Reputation: 20531

  1. Check that a JDK 17 is available at File -> Project Structure -> Platform Settings -> "SDKS"
    File -> Project Structure -> Platform Settings -> "SDKS"

  2. Select the 17 JDK at File -> Project Structure -> Project Settings -> "Project"
    File -> Project Structure -> Project Settings -> "Project"

  3. File -> Invalidate Caches... -> (leave defaults) -> "Invalidate and Restart"

  4. Do "Build" -> "Rebuild Project"

Upvotes: 18

Daniel McEnnis
Daniel McEnnis

Reputation: 21

Your error is likely from IntelliJ attempting to call a Java 17 parser for compliance with Java 17 syntax (regardless of the SDK type) and there is no Java 17 JDK installed to perform the syntax checking with. You have 2 options.

Change 'Language Level' (Project Settings / Project in the Module Settings available from context window - right click - in the project window) to match your current SDK (ignoring possible language conflicts with more recent versions)

Download a Java 17 JDK to perform parsing with. That is in Platform Settings/SDKs in the same context menu, select '+', select 'Download JDK', then download and install a Java 17 version.

Upvotes: 2

Russ115415
Russ115415

Reputation: 1

I solved this by lowering language level

Upvotes: -1

JustAC0der
JustAC0der

Reputation: 3169

I had the same problem. What helped in my case is the following. In IntelliJ IDEA I opened File -> Project structure and then clicked Modules and changed the Language level to 17. Then I was able to run my code without problems.

Project structure window

Upvotes: 37

user3177190
user3177190

Reputation: 11

For similar thing happened when upgrading to java 17. I had it changed everywhere else (suggested by other answers) but in the main maven project .iml file there was still reference to openjdk-16. After manually fixing that to "openjdk-17" it started working well

Upvotes: 1

Radi
Radi

Reputation: 6614

This issue happened to me while upgrading to Java 17, I solved it by configuring the new SDK in project structure and invalidate the caches : File --> invalidate caches --> default selection and restart.

Upvotes: 13

edine-noella
edine-noella

Reputation: 129

I have faced the same error while trying to use version 16.This is because the new version you are trying to use is unstable.

  1. you have to uninstall the version 17 go to: file -> project structure -> SDKs .delete sdk 17 by right clicking on it and then delete. right click on highlighted version(in your case its 17)

  2. now you have to change project sdk go to: file -> project structure -> project . select the previous version which use to work for you , in my case its 15 java version "15.0.2". set project language level to default (SDK default(15-Text blocks))

    changing project sdk and project language level

  3. the last part is to change the project configuration sdk go to your navigation bar where you debug your project then select edit configurations . select the sdk 16 for your project (in my case its 15) to change the project configuration sdk

Upvotes: 10

Viacheslav Zholnovach
Viacheslav Zholnovach

Reputation: 21

In my case, updating .idea/misc.xml didn't help. I was upgrading from Intellij 2020.2 -> Intellij 2020.4 -> Intellij 2020.1.1. Ended up with a reset: File -> Manage IDE Settings -> Restore Default Settings...

Upvotes: 2

Boulder_on
Boulder_on

Reputation: 51

In order to fix this I had to change the Ant build setting Execution -> Jun under JDK. For some reason the default was JDK 11, everywhere else I has specified JDK 16. Once I set this to JDK 16 the problem went away.

Upvotes: 1

hawkeye
hawkeye

Reputation: 35752

I had this issue when I was using the default Ant run. When I switched the project to maven with the maven-compiler-plugin with java version set this issue went away.

Upvotes: 1

CrazyCoder
CrazyCoder

Reputation: 402403

See this answer for the relevant screenshots. Make sure all the source/target levels are configured correctly in all the dialogs. It may be a typo somewhere and 17 is used instead of 1.7 (Java 7).

Inspect .idea/misc.xml file in the project directory, make sure it specifies the correct versions. See also the language levels specified in *.iml module files and in .idea/compiler.xml file.

Upvotes: 4

Related Questions