Java
Error Java invalid target release 11 - IntelliJ IDEA
Encountering the “Error: Java: invalid target release: 11 - IntelliJ IDEA” message can be a frustrating roadblock for developers, often halting progress and causing confusion. This error typically signifies a mismatch between the Java Development Kit (JDK) version configured for your project or module and the bytecode version it’s trying to compile or run. Specifically, “invalid target release: 11” indicates that your project is configured to compile code for Java 11, but the underlying compiler or environment is set to an older version, or vice-versa. Understanding the root causes and systematic troubleshooting steps is crucial for resolving this issue swiftly and getting your development workflow back on track. This guide will walk you through diagnosing and fixing this common IntelliJ IDEA error, ensuring your Java projects compile and run smoothly.
Understanding the “invalid target release: 11” Error
The “invalid target release” error primarily stems from a discrepancy in Java versions. When you compile Java code, the compiler (javac) translates your source files into bytecode, which is then executed by the Java Virtual Machine (JVM). Each Java version, like Java 8, 11, or 17, has a specific bytecode version. If your project is configured to target Java 11 (meaning it expects to produce or consume Java 11 compatible bytecode), but IntelliJ IDEA or your build system uses a JDK that is older than Java 11 (e.g., Java 8), this error will occur. Conversely, if your project settings specify an older target release but the SDK is newer, while less common, it can sometimes still lead to unexpected behavior or compilation issues.
This incompatibility often manifests in environments where multiple JDKs are installed on the same machine, or when developers switch between projects requiring different Java versions. For instance, a legacy project might require Java 8, while a new microservice demands Java 11 or higher. Without careful configuration, IntelliJ IDEA might pick up a default or incorrect JDK, leading to the dreaded “invalid target release: 11” message. It’s a clear signal that your project’s language level mismatch needs immediate attention, highlighting the critical importance of a properly configured Java SDK within your IDE.
Why This Mismatch Occurs
The core reason for this error is a lack of alignment across three key settings: the Project SDK, the Project Language Level, and individual Module SDKs/Language Levels. IntelliJ IDEA provides comprehensive settings to manage these, but they must be consistent. Developers might encounter this when importing a project, updating their JDK, or sharing projects across teams with varying environments. As noted by JetBrains, proper SDK configuration is foundational for any Java development, and inconsistencies can easily lead to compilation failures. Ensuring your compiler version error is resolved requires a holistic check of these settings.
Diagnosing the Problem in IntelliJ IDEA
Pinpointing the exact source of the “invalid target release: 11” error within IntelliJ IDEA involves systematically checking several configuration points. This IDE is highly configurable, which is powerful but can also be a source of version conflicts if not managed carefully. The most common culprits are misconfigured Project SDK settings, incorrect Language Level assignments, or inconsistencies at the module level. Effective diagnosis requires a clear understanding of where these settings reside and how they interact.
A quick initial check often involves looking at the project structure. If your project has multiple modules, each module can potentially inherit or override the project-level SDK settings, leading to localized errors. For example, one module might be correctly configured for Java 11, while another, perhaps an older utility module, is still trying to compile with Java 8, triggering the compiler version error when the main project attempts to use its output. Understanding this hierarchy is essential for effective troubleshooting and ensuring JVM compatibility across your entire codebase.
Checking Project SDK and Language Level
The first place to look is your Project Structure settings. Access this by going to File > Project Structure... (or pressing Ctrl+Alt+Shift+S on Windows/Linux, &8984;+; on macOS). Under the “Project” section, you’ll find “Project SDK” and “Project language level.” The “Project SDK” defines the JDK that IntelliJ IDEA uses for compiling, running, and debugging your entire project. The “Project language level” specifies the Java version features your code can use. For “invalid target release: 11,” ensure both are set to a compatible Java 11 SDK and a language level of 11 or higher. If you need assistance with specific Java language features, consider reviewing an article on advanced Java concepts for further insights.
Module-Specific Configurations
Even if your Project SDK is correct, individual modules can override these settings. Within the same “Project Structure” dialog, navigate to the “Modules” section. Select each module in your project and check its “Dependencies” and “Sources” tabs. In “Dependencies,” ensure the “Module SDK” is set to “Project SDK” (which should be Java 11) or explicitly to a Java 11 SDK. In “Sources,” verify the “Language level” is also set to 11 or higher. These IntelliJ IDEA settings are critical because a single misconfigured module can cascade the “invalid target release: 11” error throughout your project, causing compilation failures even if other parts are correctly configured. This granular control is vital for managing complex multi-module projects.
Step-by-Step Solutions to Resolve the Error
Resolving the “Error: Java: invalid target release: 11 - IntelliJ IDEA” typically involves adjusting your project’s SDK and language level settings to ensure consistency. This process is straightforward but requires attention to detail across various configuration points within IntelliJ IDEA. By following these steps, you can systematically eliminate the common causes of this compiler version error and restore your development environment to a functional state. Often, the issue is not a missing JDK, but rather that IntelliJ IDEA is simply pointing to the wrong one or an outdated version.
It’s important to remember that changes to project structure often require a project re-import or a re-build to take full effect. IntelliJ IDEA provides robust tools for managing these configurations, making it relatively easy to switch between different Java SDK versions as needed for various projects. However, a common pitfall is forgetting to apply changes or overlooking a specific module’s setting. Always confirm that your chosen Java SDK configuration is applied uniformly across all relevant parts of your project for seamless compilation and execution.
Adjusting Project and Module Settings
To fix the “invalid target release: 11” error, follow these steps meticulously:
- Open Project Structure: Go to
File > Project Structure...(Ctrl+Alt+Shift+Sor&8984;+;). - Configure Project SDK: In the “Project” tab, locate “Project SDK.” If it’s not set to Java 11 (or a higher compatible version like 17 or 21, if that’s your target), click “New…” to add your Java 11 JDK installation path, or select an existing Java 11 SDK from the dropdown.
- Set Project Language Level: Immediately below “Project SDK,” set “Project language level” to “11 - Local variable type inference, etc.” (or the corresponding level for your chosen JDK).
- Check Module SDKs: Navigate to the “Modules” tab. For each module listed, ensure its “Module SDK” is either set to “Project SDK” or explicitly points to your Java 11 SDK. Also, verify that the “Language level” in the “Sources” tab for each module is set to 11.
- Verify Build Tools Settings: If you use Maven or Gradle, ensure their configurations also align. For Maven, check your
pom.xmlfor properties like<maven.compiler.source>11</maven.compiler.source>and<maven.compiler.target>11</maven.compiler.target>. For Gradle, look inbuild.gradleforsourceCompatibility = '11'andtargetCompatibility = '11'. After making changes, refresh your Maven/Gradle project in IntelliJ IDEA. - Apply Changes and Rebuild: Click “Apply” and then “OK” to save your settings. Finally, go to
Build > Rebuild Projectto ensure all changes take effect. This comprehensive approach addresses the Java SDK configuration and language level mismatch effectively.
Ensuring Correct JDK Installation
Sometimes the issue isn’t just misconfiguration but an improperly installed or missing JDK. Ensure you have Java 11 installed correctly on your system. You can verify this by opening a terminal or command prompt and typing java -version and javac -version. Both should report version 11. If they don’t, you may need to download and install a Java 11 JDK from a reputable source like Oracle (for LTS versions) or OpenJDK distributions like Adoptium. Setting your system’s JAVA_HOME<b>Question & Answer : </b><br></br><p>I am trying to build an application which was built using java 8, now it's upgraded to java 11. I installed <a href="https://www.oracle.com/technetwork/java/javase/downloads/index.html" rel="noreferrer">Java 11</a> using <a href="https://docs.oracle.com/en/java/javase/11/install/installation-jdk-microsoft-windows-platforms.html#GUID-A7E27B90-A28D-4237-9383-A58B416071CA" rel="noreferrer">an oracle article</a> in my <strong>windows machine</strong> and I use <strong>IntelliJ IDEA 2017</strong> as my IDE.</p> <p>I changed my system environment variables and set the </p> <pre>JAVA_HOME to C:\Program Files\Java\jdk-11.0.1 </pre> <p>And added that to the Path variable.</p> <pre>C:\>java -version java version "11.0.1" 2018-10-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode) </pre> <p>When I build my application in IntelliJ, this is what I get:</p> <pre>Information:java: Errors occurred while compiling module 'test-domain_main' Information: javac 1.8.0_171 was used to compile java sources Information:1/10/2019 4:21 PM - Compilation completed with 1 error and 0 warnings in 1s 199ms Error:java: invalid target release: 11 </pre> <p>This is what I've tried so far:</p> <ol> <li><p>I changed .idea/compiler.xml target values from 8 to 11 but that didn't help. Also, verified the Target bytecode version in settings > Build, Execution, Deployment > Compiler > Java Compiler and all my modules are set to 11. </p></li> <li><p>Went to file > Project Structure > SDKs *(currently I have 1.7 and 1.7 listed)* > Add new SDK > JDK > After that, I selected C:\Program Files\Java\jdk-11.0.1 But it errors out with "The selected directory is not a valid home for JDK"</p></li> </ol> <p>I am not sure if I installed the wrong JDK 11, because in my C:\Program Files\Java\, I see separate JDK and JRE folders for 1.7 and 1.8 but only JDK folder for 11.0.1</p> <p>Or is it something else I need to change? </p><br></br><p>I've got the same issue as stated by Gryu. Same Intellij 2018 3.3</p> <p>I was able to start my project by setting (like stated by Grigoriy)</p> <pre>File->Project Structure->Modules ->> Language level to 8 ( my maven project was set to 1.8 java) </pre> <p>AND</p> <pre>File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> 8 also there </pre> <p>I hope it would be useful</p>