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
1 2 3 4 |
Information:java: Errors occurred while compiling module Information:javac 7 was used to compile java sources Information:03/02/19 07:35 - Compilation completed with 1 error and 0 warnings in 1 s 529 ms Error:java: invalid source release: 8 |
The reason is that your project/module JDK version does not match the intellij project version and below steps to fix it :
- Open your IntelliJ and navigate to File -> Project Structure -> Project Settings (Ctrl + Alt + Shift + S)
- In the Project SDK section, select the SDK that matches your code. (My code targets Java 1.8, so I select Java 1.8)
- 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
- 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
That’s it. Your project should build without problem now.