When using the maven command to create a simple Maven project (with the latest versions of maven and java), I get the error:
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
So, what change is needed to fix this. Do I change the maven command or edit the pom.xml file afterwards?
To reproduce the error
First verify what versions of Java and Maven you are running.
At the time of this question, I'm using the latest versions of Maven and Java.
Maven: 3.8.4 and Java 17.0.2
Below are details
mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: D:\p\apache-maven-3.8.4
Java version: 17.0.2, vendor: Oracle Corporation, runtime: D:\p\jdk-17.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
java -version
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
Create the maven hello world-like program
I used this command to create the Java maven sample program.
mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
I found the following link which explains this in more detail (if needed). https://facingissuesonit.com/2017/06/06/how-to-create-maven-java-console-project/.
Build the code
Next, build the code and observe the error.
cd helloworld
mvn clean install
[ERROR] COMPILATION ERROR :
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
Notice the ERRORs.
But, if I switch back to Java 8 (JDK 1.8) and run the maven build command, then the code compiles successfully. Below is the successful compile and the maven version and JDK version used that result in a successful compilation.
mvn clean install
[INFO] BUILD SUCCESS
mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: D:\p\apache-maven-3.8.4
Java version: 1.8.0_271, vendor: Oracle Corporation, runtime: D:\p\jdk1.8.0_271\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
My question is, how do I fix this? and Why does this happen?