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 instructions
- Added - mvnto- PATHbefore compiling
- Reinstalled Maven 3.8.1 
- Reinstalled JDK8 and reset - JAVA_HOME& added mvn to- PATHagain before compiling
- Added - sudoto my command. In fact before adding- sudo, 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 -vgive me the output below- Maven 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 -versiongave 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_HOMEpoints to the JDK and not the JRE by consulting Maven's documentation
 
    