Question
What does the error 'java: invalid source release 1.9' mean and how can I resolve it in IntelliJ IDEA?
Error message displayed upon compilation.
Answer
The error 'java: invalid source release 1.9' in IntelliJ IDEA typically indicates that your project is set to use an incompatible Java version. This can occur if your project's settings don't match the installed Java version on your system or if you're using an outdated version of the Java SDK that does not support Java 9 features.
// Example of including the correct SDK in your build.gradle for a Java project:
apply plugin: 'java'
sourceCompatibility = '9'
targetCompatibility = '9'
Causes
- The project is configured to use a JDK version that does not support Java 9.
- The IntelliJ IDEA settings do not align with the installed Java version on your system.
- Some dependencies might require a different Java version, leading to conflicts.
Solutions
- Verify the installed JDK version on your machine and ensure it supports at least Java 9.
- In IntelliJ, go to 'File' > 'Project Structure' > 'Project' and ensure that the Project SDK is set to a JDK that supports Java 9 or higher.
- In the same 'Project Structure' window, check the 'Modules' section and make sure each module's language level is set correctly to 9 or the compatible version you need.
- Use this path: 'File' > 'Build, Execution, Deployment' > 'Compiler', and set the targeted bytecode version to 9 where necessary.
Common Mistakes
Mistake: Setting the Project SDK to an older version of the JDK (like 1.8) while trying to use features from Java 9.
Solution: Update the Project SDK in IntelliJ's Project Structure to a version that supports Java 9.
Mistake: Forgetting to sync or refresh project configurations after changing SDK settings.
Solution: Run 'File' > 'Sync Project with Gradle Files' or reload the project to ensure the changes take effect.
Helpers
- IntelliJ IDEA
- Java invalid source release
- fix Java version issues
- Java SDK configuration
- IntelliJ project structure