Fatal Error Maven Not Suporting Java 11

Maven is not using Java 11: error message “Fatal error compiling: invalid target release: 11”

Introduction:

Maven is a build automation tool used primarily for Java projects to manage the build lifecycle and dependencies.

Overview:

When Maven is not using Java 11 and throws an error message like “Fatal error compiling: invalid target release: 11”, it typically means that Maven is configured to compile the code for a different Java version than the one specified in the project’s settings.

Problem:

The error message “Fatal error compiling: invalid target release: 11” indicates that the compilation target for the Java source code is set to a version that is not recognized by the current Maven configuration.

Solution:

To resolve this issue, ensure that Maven is configured to use Java 11 as the target release for compilation.

This can be done by setting the `maven.compiler.source` and `maven.compiler.target` properties in the Maven project’s `pom.xml` file to 11. Additionally, make sure that the JAVA_HOME environment variable is set to the correct JDK version (in this case, Java 11).

Key points to address:

– Ensure Java 11 is installed on the system and the JAVA_HOME environment variable is set correctly.

– Check the JAVA_HOME path in the Maven configuration to point to the Java 11 installation.

– Update the Maven compiler plugin and the source/target configurations to Java 11.
– Verify that the project’s pom.xml specifies Java 11 as the target release.

– Restart Maven after making these changes to ensure they take effect.

Explain the Core Concept:

Error message “Fatal error compiling: invalid target release: 11” indicates that the version of Java being used in your Maven project is not compatible with the target release specified.

Maven is not able to compile the code using Java 11 because it is set to target a different version.

You need to update the Maven compiler plugin configuration to use Java 11 as the target release.

Different Solutions with code samples:

1. Update Maven Compiler Plugin in pom.xml to set source and target versions to Java 11:


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

2. Check JDK configuration for Maven:
Make sure that your JAVA_HOME environment variable is set to the JDK 11 installation directory.

3. Update the Java version in your IDE:
Ensure that your IDE is configured to use JDK 11 as the project SDK.

Conclusion:

By updating the Maven Compiler Plugin configuration and ensuring the correct JDK configuration, you can resolve the issue of Maven not using Java 11 and encountering the error message “Fatal error compiling: invalid target release: 11”.

Leave a Comment

Your email address will not be published. Required fields are marked *