Question
How can I fix the 'Error: Java: invalid target release: 11' in IntelliJ IDEA after upgrading from Java 8 to Java 11?
// Not applicable for this issue.
Answer
The 'Error: Java: invalid target release: 11' in IntelliJ IDEA typically occurs when the project is configured to use an incompatible Java version. This issue arises especially when a project initially built with Java 8 is upgraded to Java 11, but the environment setup is incorrect or incomplete.
// Setting up Project SDK in IntelliJ IDEA
// Ensure the following step is taken to configure JDK properly in IntelliJ
// 1. Go to File > Project Structure > Project.
// 2. Choose 'Project SDK' and select JDK 11 from the dropdown list.
Causes
- Mismatched Java SDK configuration in IntelliJ IDEA and system environment variables.
- Incorrect project structure settings, specifically targeting bytecode versions.
- Installation of Java 11 may not have been done properly, leading to IntelliJ not recognizing it.
Solutions
- Verify that the project JDK is set to JDK 11 in IntelliJ IDEA. Go to 'File' > 'Project Structure' > 'Project', and ensure the Project SDK is JDK 11.
- Clear and reset any Java version settings in 'File' > 'Project Structure' > 'SDKs'. Ensure to delete previous SDK entries that may conflict (like JDK 7 or 8).
- Reinstall JDK 11 using the official Oracle installer to ensure the installation is valid and complete. Ensure that both JDK and JRE are installed.
- Check the 'Targets bytecode version' under 'File' > 'Project Structure' > 'Modules'. Ensure that it is set to 11 for all modules.
Common Mistakes
Mistake: Not setting the correct Project SDK to JDK 11 after upgrade.
Solution: Check and update the Project SDK from 'File' > 'Project Structure' > 'Project'.
Mistake: Having remnants of older JDK versions or incorrect paths.
Solution: Remove older JDK paths from the system environment variables and ensure they point only to JDK 11.
Mistake: Inconsistent module settings related to Java Compiler.
Solution: Go to 'File' > 'Project Structure' > 'Modules' and double-check each module's bytecode version settings.
Helpers
- invalid target release 11 IntelliJ IDEA
- Java 11 setup IntelliJ
- fix Java invalid target release
- IntelliJ Java version error
- upgrade Java 8 to 11 IntelliJ