Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij - Error:java: invalid source release: 1.8

While trying to run tests, I ran into this compilation error:

invalid source release: 1.8

I tried researching this on Google and here, and after applying all of the solutions that worked for others this issue still persists. Here is what I have done so far:

  • Preferences -> Java Compiler: set 'project bytecode version' to 1.8
    • I also set the target bytecode version to 1.8 for each individual module as well
  • Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner: Set JRE to use Project JDK (which correctly displays as 1.8)
  • Project Structure -> Project: set Project SDK to 1.8 and language level to 8
  • Project Structure -> Modules -> Sources: set language level to 8 for each module
  • Project Structure -> Modules -> Dependencies: set Module SDK to 1.8

I think this issue may have something to do with a discrepancy between the JDK and the compiler. When I run java -version from the terminal it returns 1.8.0_111. However when I run javac -version it returns 1.7.0_79. I looked for ways to force change the javac version to match the java version but nearly all of them reference update-alternatives which is not available for Mac OS or removing /usr/bin which is not allowed (even with sudo) on El Capitan.

Workaround Edit:
I was able to bypass the issue by going to Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler and changing the compiler from "javac" to "Eclipse" and I am able to compile my project.

like image 559
Marsipan Avatar asked Nov 18 '16 15:11

Marsipan


3 Answers

  1. Install jdk1.8.*
  2. Change SDK to jdk1.8.*
  3. Done
like image 180
Tim Lin Avatar answered Nov 08 '22 22:11

Tim Lin


Try to change java version at the terminal, try this: change-java 8

like image 1
isabelaterribili Avatar answered Nov 08 '22 22:11

isabelaterribili


On IntelliJ:

  • Click on "File" menu
  • Click on "Settings" sub-menu.
  • On the Settings window, click to expand "Build, Execution, Deployment"
  • Expand "Build Tools"
  • Click on "Gradle"
  • On Gradle JVM, select the Java version you wish to use

IntelliJ Settings - Gradle Configuration Image

like image 1
acarlstein Avatar answered Nov 08 '22 23:11

acarlstein