Maven suddenly stopped compiling with the error below. It was working this morning and I'm not sure what caused this.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ExampleProject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Basic Information:
- OS: Mac
- Machine: MacBook Pro
- Java: 1.8.0_201 (jdk8)
- Maven: 3.8.1
What I tried:
- Checked for existence of Java compiler
$ javac -version
javac 1.8.0_201
Check
$JAVA_HOME
: I got/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
, which is correct for Mac OS according to Maven's installation instructionsAdded
mvn
toPATH
before compilingReinstalled Maven 3.8.1
Reinstalled JDK8 and reset
JAVA_HOME
& added mvn toPATH
again before compilingAdded
sudo
to my command. In fact before addingsudo
, I was facing some sorta "failed to delete something" error.Restarting my laptop without using the "Reopen windows...." option.
Adding the compiler option to
pom.xml
(I didn't need this when it was working this morning)Running
mvn -v
give me the output belowMaven home: /opt/apache-maven-3.8.3 Java Version: 1.8.0_201, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
Running
java -version
gave me the output below:java version "1.8.0_201" Java (TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot (TM) 64-Bit Server VM (build 25.201.b09, mixed mode)
Additional Info:
I am not using any IDE like Eclipse/IntelliJ/NetBeans. Just purely on terminal. Please base your answers on this.
It seems like there are 2 versions of Maven on my system, probably due to the reinstall. But prior to the reinstall, this problem already started
Reference (I've tried the solutions in here too)
https://roufid.com/no-compiler-is-provided-in-this-environment/
Edit
- I have already made sure that
JAVA_HOME
points to the JDK and not the JRE by consulting Maven's documentation