This may not be the same mistake, but I had a similar one.
Check Maven Java Version
Since Maven also works with Java, first check which version your Maven is running on:
mvn --version | grep -i java
Returns:
Java version 1.8.0_151, vendor: Oracle Corporation, runtime: C: \ tools \ jdk \ openjdk1.8
Incompatible version
Here above, my maven runs with Java Version 1.8.0_151 . So even if I tell maven to compile with Java 11 :
<properties> <java.version>11</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> </properties>
This will logically output this error:
[ERROR] Failed to fulfill the target org.apache.maven.plugins: Maven-compiler-plugin: 3.8.0: compile (default-compile) for the project efa-example-commons-task: Fatal error compilation: invalid target release: 11 → [Help1]
How to install a specific version of Java for Maven
The logical thing to do is install a higher version of Java in Maven (e.g. Java version 11 instead of 1.8).
Maven uses the JAVA_HOME environment variable to find the version of Java to run. Therefore, change this variable to the JDK with which you want to compile (for example, OpenJDK 11).
Health Check
Then run mvn --version again to make sure the configuration has been taken care of:
mvn --version | grep -i java
gives
Java version: 11.0.2, vendor: Oracle Corporation, runtime: C: \ tools \ jdk \ openjdk11
Which is much better and more correct for compiling code written with Java 11 specifications.