How to Fix Error:Java: Javactask: Source Release 1.8 Requires Target Release 1.8

Sheeraz Gul Feb 02, 2024
How to Fix Error:Java: Javactask: Source Release 1.8 Requires Target Release 1.8

While using IntelliJ for Java, it is a common problem that we cannot compile Java programs. This tutorial provides a solution to this error.

Error:Java: Javactask: Source Release 1.8 Requires Target Release 1.8

If you cannot compile a Java program in IntelliJ, most of the time, the problem is that the source release is not matched to the target release.

We must match the source release to the target release to solve this problem. Here are the solutions for different platforms of IntelliJ.

Solution for Windows

Follow the steps below to solve Windows’ source release requires target release error.

  • Go to the File menu of IntelliJ.
  • Select Settings from the File menu.
  • Select Build, Execution, Deployment from the Settings menu.
  • Select Compiler from Build, Execution, Deployment.
  • Select Java Compiler from Compiler.
  • Now, on the Java Compiler page, select Javac in Use compiler.
  • Select your version in the Project bytecode version. Make sure it is similar to the Target bytecode version.
  • For example, for Project bytecode version 1.8, the Target bytecode version will also be 1.8.
  • Click Apply, then Ok, and you are good to go. See the screenshot for this method.

Java Compiler Settings

The shortcut to open the Java compiler directly is to press Ctrl+Shift+A and then type Java compiler and finally press Enter.

Solution for MacOS

Follow the steps below to solve the source release requires target release error on macOS.

  • Go to the IntelliJ menu.
  • Select Preferences.
  • Select Build, Execution, Deployment from Preferences.
  • Select Java Compiler from Build, Execution, Deployment.
  • Now, on the Java Compiler page, select Javac in Use compiler.
  • Select your version in the Project bytecode version. Make sure it is similar to the Target bytecode version.
  • For example, for Project bytecode version 1.8, the Target bytecode version will also be 1.8.
  • Click Apply, then Ok, and you are good to go.

Solution for Maven

For Maven, we need to add the compiler to pom.xml in the top-level project node. Open your pom.xml and add the code below.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Once you add the plugin to pom.xml, save it, and you are ready.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - Java Error