Encountering the “java: invalid source release 1.9” error in IntelliJ IDEA can be a frustrating roadblock for any Java developer. This specific message often indicates a mismatch between the Java Development Kit (JDK) version used to compile your code and the language level configured for your project or module. While it might seem daunting at first, this error is typically straightforward to resolve once you understand its root cause. This guide will walk you through diagnosing and fixing the “IntelliJ IDEA - Error: java: invalid source release 1.9” issue, ensuring your development workflow remains smooth and efficient.
Understanding the “invalid source release” Error
The “invalid source release 1.9” error signals a fundamental misunderstanding between your project’s configuration and the Java environment you’re using. Specifically, it means your project or module is set to compile code using Java 9 features or syntax, but the JDK IntelliJ IDEA is pointing to for compilation does not support Java 9 or later. This discrepancy often arises when you’ve upgraded your local JDK, imported an older project, or when a build tool like Maven or Gradle has an outdated configuration.
Java development relies heavily on backward compatibility, but forward compatibility is not guaranteed. A Java 8 compiler, for instance, cannot process code written with Java 9 features, hence the “invalid source release” error. Each Java release introduces new language features, APIs, and JVM improvements. For example, Java 9 brought modules (Project Jigsaw), which fundamentally changed how applications are structured and compiled. If your project’s language level is set to Java 9, but your compiler is still Java 8, it simply won’t understand the new syntax or module path configurations.
According to Oracle’s official documentation on Java versions, maintaining consistent JDK versions across your development environment, build tools, and project settings is crucial for avoiding compilation errors. This particular error highlights the importance of aligning your project’s expected Java version with the capabilities of the JDK you’re using. Even if you have multiple JDKs installed, IntelliJ IDEA needs to be explicitly told which one to use for a given project or module.
Diagnosing the Problem in IntelliJ IDEA
The first step to resolving the “IntelliJ IDEA - Error: java: invalid source release 1.9” is accurately diagnosing where the version mismatch lies within your IntelliJ IDEA setup. There are several key places where Java versions are configured, and a single inconsistency can trigger this error. It’s essential to check these settings systematically to pinpoint the exact conflict.
The most common areas to investigate include your Project SDK, Module SDKs, and the Language Level settings. Your project’s SDK defines the default JDK for the entire project, while module SDKs can override this for specific modules, allowing for mixed-version projects. The language level, on the other hand, dictates which Java language features the compiler should expect and support. For instance, if your project’s language level is set to 9 (or higher), but your Project SDK is pointing to JDK 8, you’ll encounter this error. Similarly, a module might be configured for Java 9, but its specific module SDK is still set to an older version.
To start your diagnosis, navigate to File > Project Structure (or press Ctrl+Alt+Shift+S). Within this dialog, you’ll find various sections crucial for Java version management:
- Project SDK: Under the “Project” tab, ensure the “Project SDK” is set to a JDK that supports Java 9 or higher (e.g., JDK 11, JDK 17, or a specific JDK 9 installation).
- Project language level: Also under the “Project” tab, verify that the “Project language level” matches your chosen Project SDK or is set to a version compatible with it (e.g., if using JDK 11, setting language level to 11 or lower is fine).
- Module SDKs and Language Levels: Go to the “Modules” tab. For each module, check its “Module SDK” and “Language level.” These settings can sometimes override the project-level configurations, leading to localized errors. Make sure these are consistent with the desired Java version.
- Build Tools Configuration: If you’re using Maven or Gradle, their configurations can also dictate the Java version. Check your
pom.xml(for Maven) orbuild.gradle(for Gradle) files forsourceandtargetcompatibility settings. These files can often override IntelliJ’s GUI settings if not aligned.
Once you identify the discrepancy, you’re ready to apply the fix. This detailed check ensures you don’t miss any subtle configuration that might be causing the “invalid source release 1.9” problem.
Step-by-Step Solution: Resolving the Error
Resolving the “java: invalid source release 1.9” error in IntelliJ IDEA typically involves aligning your project’s Java configurations. The key is to ensure that the JDK used for compilation supports the language level set for your project and its modules. Here’s a structured approach to fix it:
- Verify Installed JDKs: First, ensure you have a Java Development Kit (JDK) version 9 or higher installed on your system. If not, download and install a stable version like OpenJDK 11 or Oracle JDK 17 from a trusted source. You can find OpenJDK distributions from Adoptium (formerly AdoptOpenJDK) at adoptium.net.
- Configure Project SDK:
- Open IntelliJ IDEA. Go to
File > Project Structure(or pressCtrl+Alt+Shift+S). - In the “Project Structure” dialog, select “Project” under “Project Settings” on the left.
- Under “Project SDK,” click the dropdown. If your desired JDK (e.g., 9, 11, 17) is not listed, click “Add SDK” > “JDK” and navigate to the installation directory of your Java 9+ JDK. Select it and click “OK.”
- Ensure the “Project SDK” is now set to your Java 9 or higher JDK.
- Open IntelliJ IDEA. Go to
- Set Project Language Level:
- Still in the “Project” section of “Project Structure,” locate “Project language level.”
- Select the language level that matches your Project SDK or is compatible with it (e.g., “9 - Modules, private interface methods, etc.” or “11 - Local-Variable Syntax for Lambda Parameters”). It’s generally best to match the SDK version.
- Configure Module SDKs and Language Levels:
- Go to the “Modules” section under “Project Settings” in the left pane.
- For each module listed, select it. On the right, ensure that “Module SDK” is set to “Project SDK” or explicitly to a Java 9+ JDK.
- Verify that the “Language level” for each module is also set appropriately (e.g., “9” or higher). If a module requires an older Java version, you can set its language level lower, but its SDK must still be compatible with the project.
- Update Build Tool Settings (if applicable):
- For Maven: Open your
pom.xmlfile. Ensure themaven.compiler.sourceandmaven.compiler.targetproperties are set to “9” or higher. For example: ```<maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target>
package cs4321.project2; import java.io.FileReader; import net.sf.jsqlparser.parser.CCJSqlParser; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.select.Select; public class Parser { private static final String queriesFile = “resources/input/queries.sql”; public static void main(String[] args) { try { CCJSqlParser parser = new CCJSqlParser(new FileReader(queriesFile)); Statement statement; while ((statement = parser.Statement()) != null) { System.out.println(“Read statement: " + statement); Select select = (Select) statement; System.out.println(“Select body is " + select.getSelectBody()); } } catch (Exception e) { System.err.println(“Exception occurred during parsing”); e.printStackTrace(); } } }After modifying, right- **Question & Answer :** I'm trying to run my JSQL parser class, but I'm getting `Error: java: invalid source release 1.9`. I tried to following [this answer](https://stackoverflow.com/a/42650624/7327018). I changed File> Build,Execution,Deployment> Java Compiler> Project bytecode version: 1.8. However, I can't change the Module language level and Project language level to 1.8 because there's not option for that. I still get the same error below. **Error** [](https://i.sstatic.net/XlBuf.png) **Code**Select the project, then File > ProjectStructure > ProjectSettings > Modules -> sources You probably have the Language Level set at 9: [](https://i.sstatic.net/nRRA1.png) Just change it to 8 (or whatever you need) and you're set to go. Also, check the same Language Level settings mentioned above, under Project Settings > Project [](https://i.sstatic.net/x6Ub0.png)
- For Maven: Open your