Maven is not using Java 11 error message Fatal error compiling invalid target release 11
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Analyzing the Error: "Fatal error compiling: invalid target release: 11"
When using Apache Maven, a common task is to compile Java projects. However, developers sometimes encounter errors during this process. One such error is:
This message often indicates a misconfiguration in your environment regarding Java version compatibility. Understanding this error and knowing how to resolve it is crucial for smooth project development. Here, we delve into the causes of this error and explore potential solutions.
Understanding Maven and Java Compatibility
Apache Maven is a powerful build automation tool used primarily for Java projects. It manages project dependencies, builds, and documentation through a simple Project Object Model (POM) file. Maven uses the Java Compiler (Javac), and the maven-compiler-plugin allows you to define the Java version to be used for compiling your project.
If you specify a target version of Java that is not installed or recognized by the system, you will encounter the "invalid target release" error. Specifically, the error targeting Java 11 can arise from several misconfigurations.
Common Causes of the Error
- Incorrect Java Version Installed: The system might be running a Java version that does not support the target release. For example, if Java 8 is installed, it cannot compile code for Java 11.
- Maven Compiler Plugin Version: The version of
maven-compiler-pluginmay not support newer Java targets like Java 11. Ensure your project's POM file specifies a compatible version of this plugin. - JAVA_HOME Environment Variable: This variable must point to the root directory of the installed JDK version that supports your desired target release.
- Incompatible IDE Settings: Integrated Development Environments (IDEs) like IntelliJ IDEA or Eclipse might have separate configurations that conflict with the command line or POM settings.
Technical Explanation and Solutions
Checking Installed Java Version
To verify the Java version installed on your system, execute the command:
This command should confirm the Java runtime version. Execute a similar command:
This checks the Java compiler's version. Both should be at least Java 11 when targeting it.
Configuring the Maven Compiler Plugin
Ensure your POM file contains the appropriate Maven Compiler Plugin settings like this:
Version 3.8.1 or later of maven-compiler-plugin is necessary for Java 11 support.
Ensuring JAVA_HOME is Correct
Set JAVA_HOME to the correct JDK path. This can be done in a terminal or command prompt as:
For Windows, you might use:
Add this to your system's environment variables for persistence across sessions.
IDE Configuration
In your IDE, ensure that the project's SDK or JDK settings point to the correct Java version:
- IntelliJ IDEA: Go to
File -> Project Structure -> Project, and verify the SDK is set to Java 11. - Eclipse: Navigate to
Window -> Preferences -> Java -> Installed JREs, and check your active JRE is set to a Java 11 JDK.
Key Points Summary
Here's a quick reference table summarizing common issues and solutions:
| Issue | Solution |
| Java version supports a lower target release | Install Java 11 JDK and set it as default |
Incorrect maven-compiler-plugin version | Use version 3.8.1 or higher |
| Incorrect JAVA_HOME configuration | Point JAVA_HOME to JDK 11 installation |
| IDE configuration not matching the intended Java version | Update SDK/JDK settings in the IDE to use Java 11 |
Additional Considerations
- Ensure that PATH includes the correct JDK version bin directory.
- Consider using a Java version manager like
jenvorSDKMAN!to simplify switching between different JDK versions.
Conclusion
The "Fatal error compiling: invalid target release: 11" error typically results from environment misconfigurations. By ensuring the correct Java version is installed and configured, updating maven-compiler-plugin, and verifying IDE settings, developers can resolve this issue effectively. This ensures that Maven compiles projects smoothly under the intended Java version, thereby improving productivity and reliability in software development workflows.

