I'm new to a project and the project is using the maven-enforcer-plugin
.
The plugin (version 3.0.0) is configured to require Java 11
<requireJavaVersion>
<version>11</version>
</requireJavaVersion>
I also have jdk 11 on my path
$ java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)
However, when I run mvn clean verify
I get a failure saying that I'm on Java 8 when Java 11 is required
[INFO] --- maven-enforcer-plugin:3.0.0:enforce (enforce-versions) @ checkstyle ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
Detected JDK Version: 1.8.0-261 is not in the allowed range 11.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.231 s
[INFO] Finished at: 2022-04-21T18:04:07-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0:enforce (enforce-versions) on project checkstyle: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed.
-> [Help 1]
Why would I be getting this error?
In my case, my issue was that my user
JAVA_PATH
variable was configured to Java 8, but my systemJAVA_PATH
was configured for 11. It looks like maven uses the user'sJAVA_PATH
.