IntelliJ
Java 17
source release error
Java development
troubleshooting

IntelliJ: "invalid source release: 17" error and how to fix it

Codemia Knowledge Hub ·

"Invalid source release: 17" means IntelliJ IDEA is compiling the project with a JDK that does not support the Java version the project asks for, typically an older JDK such as 11 while pom.xml or build.gradle targets 17. Fix it by installing JDK 17, setting it as the Project SDK, setting the module language level to 17, and reimporting the Maven or Gradle project.

Why the error happens

The project is configured for newer Java language features than the JDK in use supports:

  • Source release compatibility: Java source releases are tied to JDK versions. JDK 17 supports Java 17 language features. An earlier JDK such as JDK 11 lacks them, so compiling fails with "invalid source release".
  • Project SDK: every IntelliJ project has a project SDK, which is the JDK used to compile and run it. If the project specifies a source version the assigned SDK does not support, you get this error.

Two situations usually lead to it:

  1. Mismatched JDK configuration: the build file (pom.xml for Maven, build.gradle for Gradle) specifies Java 17, but IntelliJ uses an older JDK.
  2. Project Structure misconfiguration: IntelliJ's Project Structure settings set a module Java version that does not match the SDK version.

Example configuration

A Maven project with this in pom.xml:

xml
1<properties>
2    <maven.compiler.source>17</maven.compiler.source>
3    <maven.compiler.target>17</maven.compiler.target>
4</properties>

fails with "Invalid source release" if IntelliJ is configured to use JDK 11.

How to fix it

  1. Check that JDK 17 is installed by running this in a terminal:
bash
      java -version
  1. Set the Project SDK:
    • Go to File > Project Structure > Project.
    • Set Project SDK to JDK 17. If JDK 17 is not listed, click "Add SDK" to add it.
  2. Set the module language level:
    • Under File > Project Structure > Modules, select your module.
    • In Language level, select the plain 17 level (shown as "17 - Sealed types, always-strict floating-point semantics" in recent IntelliJ versions) to match the source level in your build file. Avoid the "17 (Preview)" entry, which enables preview features and needs --enable-preview.
  3. Reimport the project (Maven or Gradle):
    • For Maven, click "Reimport" in the Maven tool window.
    • For Gradle, do the same in the Gradle tool window to refresh dependencies and configuration.
ElementDescription
Error TriggerProject uses Java 17 features with unsupported JDK
Primary SolutionUpdate Project SDK to a compatible JDK version
Configuration CheckEnsure pom.xml or build.gradle aligns with JDK
IntelliJ SettingsVerify SDK is set to JDK 17 in Project Structure
ToolsUse Project SDK settings, Maven/Gradle reimport

Avoiding the error in CI and across projects

  • CI/CD pipelines: configure the build environment to use the correct JDK version, so automated builds stay consistent and do not hit the same error outside local development.
  • Version management: a JDK version manager such as SDKMAN! makes switching between JDK versions easy.
  • Regular updates: keep your JDKs and IntelliJ IDEA updated for the latest features and security patches.
  • Profile-specific configuration: in multi-profile projects, make sure each profile specifies a compatible JDK version.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms