intellij idea - Error: java: invalid source release 1.9

Maven Projects - and Project Structure[imported as maven in IntelliJ]

Try - If any of below pom entries present - values should be same at java level

<java.version>16</java.version>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
  1. Project Structure -> Project language level
  2. Module -> Language level


GRADLE projects

Since we started working with GRADLE,

Build.gradle: - even below line didn't help

sourceCompatibility = '16'

I am getting this ERROR most of the time and Solution is Change Gradle JVM to XX

Preferences | Build, Execution, Deployment | Build Tools | Gradle -> JVM enter image description here


Select the project, then File > ProjectStructure > ProjectSettings > Modules -> sources You probably have the Language Level set at 9:

screenshot

Just change it to 8 (or whatever you need) and you're set to go.

Also, check the same Language Level settings mentioned above, under Project Settings > Project

enter image description here


Sometimes the problem occurs because of the incorrect version of the project bytecode.

So verify it : File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version and set its value to 8

Example


I have had the same problem. There is an answer:

  • 1.CTRL + ALT + SHIFT + S;
    1. Then go to "Modules";
    2. "Dependencies;
    3. Change "Module SDK".

Got it! Now u have Java 9!