I use IntelliJ IDEA (2018.1.2). When try to run anything I get this error "Error:java: invalid source release:". I can't compile anything.
The output of "java --version":
java 15.0.1 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
My IDE settings:
Settings -> Build, Exectution, Deployment -> Compiler -> Java Compiler -> Target bytecode version = 11
Project Structure -> Project SDK = 15.0.1
Project Structure -> Project language level = X - experimental features
Project Structure -> Modules -> Language level (root) = X - experimental features
I have tried change any parameter above to a lower value but no result. The IDE says it uses Java 8, and I don't know how to change it.
You specified different versions of Java. 11 differs from 15.0.1.
You must be consistent with your desired version of Java across several settings.
Unfortunately IntelliJ does not make it easy to specify your desired version of Java. You have to go spelunking in multiple places for multiple settings. You must make them agree.
Use either the current version (now Java 23), or one of the LTS versions: 8, 11, 17, 21, and likely 25.
As of IntelliJ IDEA 2024.3 RC…
In the IntelliJ Settings, set Build, Execution, Deployment > Compiler > Java Compiler > Project Bytecode version to Same as language level. Set Target bytecode version to your number (23 seen here). Note that Target bytecode version pop-up menu offers Same as language level but that seems to be broken.

In File > Project Structure > Project Settings > Project, set SDK. Then set Project > Language Level to SDK default.

In File > Project Structure > Project Settings > Modules, set Module SDK to Project SDK.

In your Maven POM, you should find either a pair of source & target elements, or a single release element. Set the version number there to match your other settings.
Tip: If you see source & target, the latest tooling will allow you to replace those with a single release element, if you so desire.

If you are using Gradle rather than Maven, set the version number similarly in the appropriate build configuration file.
FYI, IntelliJ can locate and download a JDK from any of multiple vendors on your behalf.
I prefer to use SDKMAN!, a nice little utility for installing JDKs, JREs, and similar software kits such as Maven & Gradle on Unix-oriented OSes such as macOS, Linux, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With