Roufid

java: invalid source release: 8 on IntelliJ

When try to compile your Java code on IntelliJ, you may get the annoying java: invalid source release: 8 error. The complete error is as follows

The reason is that your project/module JDK version does not match the intellij project version and below steps to fix it :

  1. Open your IntelliJ and navigate to File -> Project Structure -> Project Settings (Ctrl + Alt + Shift + S)
  2. In the Project SDK section, select the SDK that matches your code. (My code targets Java 1.8, so I select Java 1.8)

    java: invalid source release: 8

  3. If you have a multi module project. Sekect the correct module SDK for each module. File -> Project Structure -> Modules -> Click on the module -> Dependencies and change Module SDK to Java 1.8 for example

    java: invalid source release: 8 : Module SDK

  4. 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

    java: invalid source release: 8 Project bytecode version

That’s it. Your project should build without problem now.