21

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
helloApp
  • 449
  • 1
  • 4
  • 21
  • Have you configured your maven compiler plugin to use Java 11? https://stackoverflow.com/a/51586202/1319284 – kutschkem Sep 28 '20 at 06:06
  • @kutschkem i have modified my initial post – helloApp Sep 28 '20 at 06:31
  • What is the output of `mvn -version`? Might be related to [fatal error compiling invalid flag --module-path](https://stackoverflow.com/questions/46118716/fatal-error-compiling-invalid-flag-module-path/46119209#46119209) – Naman Sep 28 '20 at 07:09
  • might be more relevant - https://stackoverflow.com/questions/46504713/is-maven-release-plugin-compatible-with-java-9/46505764#46505764 – Naman Sep 28 '20 at 07:27
  • Have you close your console in windows and reopened it after changing the JAVA_HOME variable? – khmarbaise Sep 28 '20 at 07:51
  • 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. – meaningqo Sep 28 '20 at 08:02
  • @meaningqo yes that was the problem. now it works. If you post your answer i will give you rep ! – helloApp Sep 28 '20 at 08:17
  • 1
    done, and thank you my friend! – meaningqo Sep 28 '20 at 09:10
  • Does this answer your question? [intellij idea - Error: java: invalid source release 1.9](https://stackoverflow.com/questions/46280859/intellij-idea-error-java-invalid-source-release-1-9) – Ravi Parekh Aug 30 '21 at 15:21

4 Answers4

48

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

Hai Nguyen
  • 1,675
  • 19
  • 14
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.

meaningqo
  • 1,653
  • 10
  • 16
  • 2
    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. – bhdzllr Dec 21 '21 at 13:19
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

S Kampen
  • 41
  • 3
-5

Please check pom version point to 11 or 8