Bick
Bick

Reputation: 18521

Intellij build after gradle refresh fails on wrong java version

I am using Gradle with intellij.
I refresh Gradle and then I rebuild my project.
I get the following

enter image description here

But I get the error that I should use -source7 or higher.
I also set the following at the settings

enter image description here enter image description here

(With all of the inner modules are set to project sdk (1.8)) But I still can't rebuild or compile without this error. Any suggestions?

(obviously i deleted all my classes and jars and then Gradle refreshed and rebuild project)

Upvotes: 13

Views: 5743

Answers (4)

rdChris
rdChris

Reputation: 116

I finally resolved this issue for myself. I'm on Windows and it turns out the order in which the JDKs are listed in the Windows environment variable matter, and overrode what IDEA had set.

enter image description here

Although my project has JDK11 listed everywhere, JDK17 was still being used. I was able to finally resolve this issue by moving their ordering to list JDK11 first.

before I swapped the env var order enter image description here

after (hurray!) enter image description here

Upvotes: 0

mowwwalker
mowwwalker

Reputation: 17344

I had this problem while trying to build Android Studio. I kept getting

Tools need to be compiled with Java 1.8, you are using Java 11

Everything in the Intellij global and "Project Structure" settings was set to Java 1.8 so I couldn't figure out what was going on. For whatever reason, what ended up working was going to Build, Execution, Deployment > Build > Gradle and selecting the Amazon corretto version of Java 1.8 as installed by sdkman. This is baffling since I'd already tried selecting two other options for Gradle JVM that said 1.8 and both of those still resulted in the same error message as a result of Java 11 being used.

enter image description here

Upvotes: 0

jeankst
jeankst

Reputation: 189

Same issue; got it solved with the following:

  1. Go to: File / Settings / Build,Execution,Deployment / Build Tools / Gradle / Gradle JVM
  2. Then choose: Use JAVA_HOME

Upvotes: 18

koto
koto

Reputation: 740

As of your second screen, make sure that all your modules are using the project default SDK, like in the screen below. The module setting may somehow be set to point older java version.

enter image description here

Upvotes: 0

Related Questions