How to Change Java Version in IntelliJ IDEA
IntelliJ IDEA has two separate Java settings: the Project SDK (which JDK IntelliJ uses to compile and run) and the language level (which Java version syntax is permitted). Change both when switching Java versions.
Change the Project SDK
- Open File > Project Structure (or Ctrl+Alt+Shift+S on Windows/Linux, ⌘+; on Mac).
- Under Project Settings > Project, click the SDK dropdown.
- Select an existing SDK or click Add SDK > JDK… and browse to the JDK installation directory.
- Set the Language level to match (e.g. "21 — ...").
- Click Apply.
Add a new SDK
If the JDK you want is not listed:
- In Project Structure, click SDKs on the left.
- Click + > JDK…
- Browse to the JDK root directory (e.g.
C:\Program Files\Eclipse Adoptium\jdk-21.0.3.9-hotspoton Windows, or/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Homeon Mac). - Click OK, then select the new SDK in the Project settings.
Change language level without changing the SDK
The language level controls which syntax features are allowed. An SDK installed as Java 21 can compile at language level 17 if your codebase targets Java 17. Change it in Project Structure > Project > Language level.
Build file takes precedence
If your project uses Maven or Gradle, the build file's Java version setting overrides the IntelliJ Project SDK for actual compilation. IntelliJ reads the build file and updates its project model accordingly.
Maven — set in pom.xml:
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
Gradle — use toolchains (recommended over sourceCompatibility):
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
After editing the build file, click Load Gradle Changes (the elephant icon) or Reload Maven project.
Module-level SDK override
In a multi-module project, you can set a different SDK per module: Project Structure > Modules > select module > Dependencies tab > Module SDK. This is rarely needed — prefer build file toolchains for portability.
IntelliJ's own JDK
IntelliJ IDEA runs on its own bundled JDK (visible in Help > About > Build number). This is separate from your project SDK and you should not change it unless troubleshooting IntelliJ itself.