IntelliJ IDEA
Java
Invalid Source Release
JDK Compatibility
Development Error

intellij idea - Error java invalid source release 1.9

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

IntelliJ IDEA is a popular Integrated Development Environment (IDE) for Java development. However, developers may encounter the error message "java: invalid source release 1.9" during their workflow. This article explores the technical underpinnings of this error, its causes, and how to resolve it effectively.

Understanding the Error

The error "java: invalid source release 1.9" typically arises when there is a mismatch between the Java Development Kit (JDK) version specified in the project and the actual JDK version supported or installed on the system.

Java Versioning

Java source releases follow a specific version pattern. Java 9, officially released in September 2017, introduced several changes, such as modularization through Project Jigsaw. However, as development continues, not all newer Intellij IDEA versions or JDK installations maintain backward compatibility with older standards, including the support for 1.9 as a shorthand for Java 9 in certain contexts.

Common Causes

  1. Incorrect JDK Version: The project might be configured to use a JDK version that is not actually present or not compatible with the specified source version.
  2. Deprecated Source Level: As of more recent Java versions, specifying 1.9 might not be recognized. Instead, 9 should be used explicitly for projects targeting Java 9.

Steps to Resolve the Error

Here are some approaches to resolving this error in IntelliJ IDEA:

1. Verify and Set Correct JDK Version

  • Check Installed JDKs: Ensure that the required JDK version is installed on your system. You can check this through terminal commands:
bash
  java -version
  javac -version
  • Configure IntelliJ IDEA:
    • Go to File > Project Structure > Project.
    • Under Project SDK, select the appropriate JDK version.
    • Under Project language level, make sure it matches the JDK's version (e.g., 9, not 1.9).

2. Update Module Settings

  • Module Language Level: Navigate to File > Project Structure > Modules. Confirm that the Language level for each module corresponds with the version of Java.

3. Update Build Tools (Maven/Gradle)

For projects managed by Maven or Gradle, ensure that their respective configuration files reference the correct Java version:

Maven

In pom.xml, update the maven-compiler-plugin configuration:

xml
1<build>
2  <plugins>
3    <plugin>
4      <groupId>org.apache.maven.plugins</groupId>
5      <artifactId>maven-compiler-plugin</artifactId>
6      <version>3.8.1</version>
7      <configuration>
8        <source>9</source>
9        <target>9</target>
10      </configuration>
11    </plugin>
12  </plugins>
13</build>

Gradle

Edit the build.gradle file to specify the correct Java version:

groovy
sourceCompatibility = '9'
targetCompatibility = '9'

4. Reimport Project

After making configuration changes, it's sometimes necessary to reimport the project to ensure IntelliJ IDEA applies all changes:

  • Right-click the project root in the Project view and select Reload Project.

Troubleshooting and Tips

If issues persist, consider the following tips:

  • Environment Variables: Double-check that your JAVA_HOME environment variable points to the correct JDK installation.
  • Plugin Conflicts: Disable any IntelliJ plugins that might interfere with Java configuration or build processes.
  • IDE Updates: Ensure IntelliJ IDEA itself is up-to-date, as newer releases may fix underlying problems or improve compatibility with the latest JDKs.

Summary Table

Key AspectDescription
Error Messagejava: invalid source release 1.9
Common CausesIncorrect JDK version, Deprecated source level usage
Resolution StepsVerify JDK installation, Correct JDK setup in IntelliJ, Update build files
Configuration FilesAdjust Maven pom.xml and Gradle build.gradle
Common Commandsjava -version, javac -version
Troubleshooting TipsCheck JAVA_HOME, Disable conflicting plugins, Update IntelliJ IDEA

By ensuring that your project settings and system installations are aligned with the version requirements, you can effectively resolve the "java: invalid source release 1.9" error in IntelliJ IDEA, leading to a smoother Java development experience.


Related reading
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
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.