22

Hello so i have upgraded from java 8 to java 11 and i get this error no matter what.I am using intellij and windows 10. What i have changed to 11: 1)In Project Structure -> Project: enter image description here

2)Project Structure ->Modules enter image description here

3)My compiler module Target bytecode version is set to 11 aswell in settings->Build,Execution,Deployment -> Java Compiler.

I even changed Both environment variables respectiveley the JAVA_HOME in user variables and JAVA_HOME in system variables to jdk-11.0.8.

When i run java -version and javac -version both show that i have version 11 installed. When i try running a mvn clean package it always fails with this error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project abc: Fatal error compiling: invalid
target release: 11 -> [Help 1]

Please help me fix the error, Any help would be greatly appreciated !

L.EThis is part of the project pom

<plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <optimize>true</optimize>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                    <compilerArguments>
                        <parameters/>
                    </compilerArguments>
                </configuration>

I have also added <release>11</release> <!--or <release>10</release>--> to it but same issue remains.

9
  • Have you configured your maven compiler plugin to use Java 11? stackoverflow.com/a/51586202/1319284 Commented Sep 28, 2020 at 6:06
  • @kutschkem i have modified my initial post Commented Sep 28, 2020 at 6:31
  • What is the output of mvn -version? Might be related to fatal error compiling invalid flag --module-path Commented Sep 28, 2020 at 7:09
  • 2
    I think I have found your problem! Please check your JDK 11 Setup in IntelliJ! Even though the project SDK is called 11, it still says that your java-version is 1.8.161. Judging from this it looks like your new jdk 11 still points to your old 1.8 installation which does not now about version 11 yet. Commented Sep 28, 2020 at 8:02
  • 1
    done, and thank you my friend! Commented Sep 28, 2020 at 9:10

4 Answers 4

52

IntelliJ IDEA 2021.1.3 (Community Edition)

If you are using Gradle build tool:

File | Settings | Build, Execution, Deployment | Build Tools | Gradle

Choose your project and choose Gradle JVM version 11. enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Only I know what I did with my settings, path variables, caches and what not until I found this.
10

Please check your JDK 11 Setup in IntelliJ! Even though the project SDK is called 11, it still says that your java-version is 1.8.161. Judging from this it looks like your new jdk 11 still points to your old 1.8 installation which does not now about version 11 yet.

1 Comment

Thank you, this helped me. My Gradle still pointed to 1.8. So maybe change the Java environment variable or in my case I changed "Gradle JVM" in IntelliJ (Settings - Build, Execution, Deployment - Gradle - Gradle JVM) to 11.
2

For me the solution was setting the JAVA_HOME var. Though you mentioned it as a solution you tried it's easy to read over it. I'm working with different projects and using java 8 for a few and java 11 for another. I had to switch between these versions to get this to work

snippet from my readme

Comments

-4

Please check pom version point to 11 or 8

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.