[Fix] Git Bash Java: invalid target release: 11

So recently I set up a Quarkus project to build some APIs on my new computer, which had JDK 8 installed. When I ran the command:

./mvnw quarkus:dev

I got the following error:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.848 s
[INFO] Finished at: 2021-05-20T23:28:45+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
 quarkus-events: 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

In short, the error complained that in the pom.xml file, I set the target release to version 11:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

However, Maven couldn’t find JDK version 11 on my system. Thus, it produced the error.

Setting environment variable doesn’t work!

I’ve tried changing the SDK to version 11 in Windows’ system environment and also user’s environment variable. However, when checking java version in Git bash, the JDK is still 1.8.

How to fix?

It turned out, the fix is quite simple. All you need to do is to set the environment variable to JDK 11 in ~/.bashrc file!

So, here is the line you need to put in ~/.bashrc:

export JAVA_HOME='/c/Program Files/Java/jdk-11.0.11'

Make sure you replace the path to your own JDK.

Save the file and reload the settings by executing:

source ~/.bashrc

After that, your build should work:

Leave a comment

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