5

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.

6
  • How did you install Java on your Mac? Commented Nov 18, 2016 at 15:06
  • I downloaded Java SDK 8u111 directly from Oracle (oracle.com/technetwork/java/javase/downloads/…). Commented Nov 18, 2016 at 15:12
  • And you tried reinstalling again, followed by a reboot, to be safe? Your path and environment variables are getting messed up, seems like Commented Nov 18, 2016 at 15:14
  • I tried removing all java versions and then reinstalled 1.8.0_111, then rebooted. It is still coming up with the same error and javac is still 1.7, even though 1.7 should be gone. Commented Nov 18, 2016 at 15:53
  • You should provide your "workaround" as an answer below. Even though, I think that is the correct solution, not a workaround at all (Not sure why it says "Eclipse") Commented Nov 18, 2016 at 16:10

5 Answers 5

4
  1. Install jdk1.8.*
  2. Change SDK to jdk1.8.*
  3. Done
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this one worked for me after trying everything else suggested on SO and elsewhere.
1

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

Comments

1

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

Comments

0

I was able to successfully compile my project by going into Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler an changing the "use compiler" option from Javac to Eclipse.

Comments

0

The solution that helped me:

Under Build, Execution, Deployment > Build Tools > Gradle > Runner

Change Run tests using: from Platform Test Runner to Gradle Test Runner:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.