[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:

invalid target release 11
invalid target release 11

Just a note, you may see this error happen to other jdk version such as 17, 10, … 19

The fix is similar.

[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 the environment variable doesn’t work!

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

How to fix invalid target release: 11?

It turned out, that 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 with your own JDK.

Save the file and reload the settings by executing:

source ~/.bashrc

After that, your build should work:

Bonus: Fix invalid target release with powershell

On PowerShell, you can quickly change the JAVA_HOME environment variable temporarily using this command:

$env:JAVA_HOME='C:\Program Files\Java\jdk-19' 

In the command above, I changed the JAVA_HOME to JDK 19.

After that, I can run the application without the error.

Leave a Comment