Maven is not using Java 11 - Fatal error compiling: invalid target release: 11

Ayush Surana :

I am trying to compile my project with Java 11.

When I try to run the application with Java 8 as the Java version in pom.xml, it works fine. But when I try to run it with Java 11, it throws an error.

Fatal error compiling: invalid target release: 11

I've tried to fix it in various ways, like changing the environment variable, updating the path, and pointing %JAVA_HOME% to Java 11.

The commands and their results as on my computer are as follows:

> java -version
java version "11.0.8" 2020-07-14 LTS
> echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.8

I am using IntelliJ IDEA and have made the necessary changes as suggested in this tutorial.

My pom.xml looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>businessapplication-6963d</projectId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

When I check the Maven version, it shows JDK 1.8 as the Java version:

mvn --version
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_241\jre

How can I point Maven to Java 11? Or, if that is not the problem, how to solve this issue? I don't think that this question is a duplicate of invalid target release: 1.7, as I have already implemented the solutions provided in that thread.

Error after building the project

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Path Environment Variable is :- 
C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;
C:\Delhi 2.0\apache-maven-3.6.1\bin;
C:\Program Files\Java\jdk-11.0.8\bin;C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files\Git\cmd;D:\Flutter\flutter\flutter\bin;
C:\Users\Infinity97\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin;
C:\Users\Infinity97\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2\bin;
H:\apache-maven-3.6.3\bin;
C:\Program Files\PostgreSQL\12\bin;
C:\Program Files\PostgreSQL\12\lib;
C:\Program Files\Docker Toolbox
procrastinator :

Seems like you're having the JAVA_HOME set in your mvn.bat. It could be pointing to the older version of Java (i.e. 11 in your case).

set JAVA_HOME=C:\path\to\jdk11 try using it on the first line, before calling maven.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Heroku Fatal error compiling: invalid target release: 11

Maven Compilation Error: Fatal error compiling: invalid target release: 1.8

Maven: Fatal error compiling: invalid target release: 1.8

Java Maven assembly plugin Fatal error compiling: invalid target release 1.14

Fatal error compiling: invalid target release: 9

Why when i try push my Spring boot app to heroku it return "Fatal error compiling: invalid target release: 11"

Error: Java: invalid target release: 11 - IntelliJ IDEA

Fatal error compiling: invalid target release: 1.8 -> [Help 1]

Intellij maven project Fatal error compiling: invalid flag: --release

error with putting project on Heroku invalid target release: 11

Error compiling maven, spring: Invalid target release 13, when trying to upload project on heroku

Eclipse Maven Build Error invalid target release

Fatal error compiling: release version 10.0.1 not supported using IntelliJ IDEA and Maven

Java 11 : Error:java: invalid source release: 11 - Not sure what to do anymore

maven with JDK11: javac: invalid flag: --release

Netbeans Maven Error: javac: invalid target release: 1.7

Using Dagger with java 11 and maven

Maven: invalid target release: 12, but JAVA_HOME is set to 12

Continuously getting the java: invalid source release: 1.9 error when compiling

maven-comiler-plugin: Fatal error compiling: error: release version 17 not supported

Fatal error compiling: release version 17 not supported

Compiling Java 11 code with maven-compiler-pugin 2.2

Heroku install bad jdk (8) version in logs but good one (11) in terminal, which results in invalid target release: 11

fatal error: Python.h: No such file or directory when compiling pybind11 example

IntelliJ 2021.2.2 gives error 'java: error: invalid source release: 18' when compiling program

Xcode stuck at compiling ios ver 11 while I am using 14 as a target

Error in heroku build: invalid target release

Java 11: What is the difference between javac --release and -source and -target command line parameters?

fatal error compiling invalid flag --module-path