Error "Source option 5 is no longer supported. Use 6 or later" on Maven compile

EclipseMavenTestingTestng

Eclipse Problem Overview


I am getting the following error on $ mvn compile:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sym360: Compilation failure: Compilation failure: 
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [Help 1]

Here is the code of my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.test.app</groupId>
 <artifactId>Tset</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>Test</name>
 <url>http://maven.apache.org</url>

 <properties>
   <maven.compiler.source>6</maven.compiler.source>
   <maven.compiler.target>1.6</maven.compiler.target>
 </properties>

<build>
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.1</version>
    </plugin>
  </plugins>
</pluginManagement>
</build>
<dependencies>

<!-https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium- 
java -->
<dependency>
	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>3.14.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
	<groupId>org.testng</groupId>
	<artifactId>testng</artifactId>
	<version>6.14.3</version>
	<scope>test</scope>
</dependency>

I tried to add properties in the pom.xml code, but still getting the same error.

Eclipse Solutions


Solution 1 - Eclipse

What helped me was these lines in pom.xml file

<properties>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Solution 2 - Eclipse

Also in one of my projects, in addition to all of answers above, another try works: Just change Language level in Modules section of Project Structure [image below] Language Level

Solution 3 - Eclipse

I had same issue, the problem is with properties. Check your JavaSE version in your project, it will be displayed beside JRE System Library folder in your project. If it is 1.5, then it will throw an error. Most probably you will have a updated version, so check the version and update it. I have updated it below based on your code.

<properties>
   <maven.compiler.source>1.6</maven.compiler.source>
   <maven.compiler.target>1.6</maven.compiler.target>
 </properties>

Solution 4 - Eclipse

I had same issue and i have added below configuration in pom.xml and it works.

<build>
   <plugins>
   <plugin>
		<artifactId>maven-compiler-plugin</artifactId>
		<version>3.5.1</version>
		<configuration>
			<source>1.8</source>
			<target>1.8</target>
		</configuration>
	</plugin>
   </plugins>
   </build>

Solution 5 - Eclipse

This helped me:

  1. Right Click on Project.
  2. Click on Build path.
  3. Click on Configure Build path.
  4. It opens a Java Build path window.
  5. Click on Java Compiler in the Left side.
  6. It navigates to Java Compiler window in that to set the Compiler compliance level is set as according to your jre version(ex if java version is 1.8 then choose 1.8) as select.
  7. Click on [Apply] button.
  8. Click on [OK] button.
  9. Right click on Project > Maven > Update the project.
  10. Right click on Project > Run As > Maven install -- The pom.xml file is running and java jars are download and installed to project.
  11. Right click on Project > Run As > Maven Test -- The pom.xml file is running and java jars are download and installed to project.

Then you got the Build Success message and your maven project is created successfully.

Solution 6 - Eclipse

I think you have wrong your pom.xml:

<properties>
   <maven.compiler.source>6</maven.compiler.source>
   <maven.compiler.target>1.6</maven.compiler.target>
 </properties>

change to:

<properties>
   <maven.compiler.source>1.6</maven.compiler.source>
   <maven.compiler.target>1.6</maven.compiler.target>
 </properties>

Now depending if you are using the command line use:

> mvn clean compile

or either way(eclipse ide)

> Right click on project Run with maven>build>Goal (compile)

Solution 7 - Eclipse

adding below code in pom will resolve the issue

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  <profiles>  

Solution 8 - Eclipse

I was facing the same issue and resolved it with the lines of code below:

<properties>
   <maven.compiler.source>1.6</maven.compiler.source>
   <maven.compiler.target>1.6</maven.compiler.target>
 </properties>

Solution 9 - Eclipse

For the new Apache net Bean its a little bit different from the suggestion by SUPARNA SOMAN

  • Right Click on your Project -Hover on "set configuration" and click customize configuration -.A new dialogue box opens....
  • At the left corner where the categories are, Click on "Source"
  • At the select form on the page below, select your required version of JDK ----see image for this last step.the last step required to change jdk version

Solution 10 - Eclipse

On MacOS I have multiple versions

user> ls /Library/Java/JavaVirtualMachines/
jdk-11.0.4.jdk		jdk-12.0.2.jdk		jdk1.8.0_221.jdk

and JAVA_HOME was not defined properly so Maven used jdk-12. I have jdk-11,jdk-8, and jdk-12.

user> mvn -version
Apache Maven 3.6.1 
Maven home: /usr/local/Cellar/maven/3.6.1/libexec
Java version: 12.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
Default locale: XXX, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

So:

Define JAVA_HOME to use jdk-8.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

Try again, now maven is:

user> mvn -version
    Maven home: /usr/local/Cellar/maven/3.6.1/libexec
    Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre

and the build is:

[INFO] BUILD SUCCESS

Solution 11 - Eclipse

I fixed this by adding this in pom.xml file:
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

Solution 12 - Eclipse

Here is the solution which helped me:

I had the same issue on error source option 5 is no longer supported, Use 6 or later

So i followed these instructions and problem SOLVED

  1. Open Project Properties (File Menu)
  2. Change the Source / Binary Format to the latest version (JDK 7 in my case)

Project Properties enter image description here

Source / Binary Format enter image description here

Clean and Build, Then Run the project

Solution 13 - Eclipse

None of the solutions above worked for me.

For some reasons the file with the name of my project.iml had changed. Found the difference in the previous subversion repository submission...

In projectname.iml I found this line:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_5">

And all I had to do was changing it to 11

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

Solution 14 - Eclipse

If in Eclipse, Write click on project and go to properties. Search for maven and configure a jdk higher version (1.7 onwards) there and apply. Now try maven install.

Solution 15 - Eclipse

In my case, running MacOS Big Sur and JDK version 15, I added the code below in pom.xml file shown below. I added the 15 for my JDK version.

<properties>
   <maven.compiler.source>15</maven.compiler.source>
   <maven.compiler.target>15</maven.compiler.target>
 </properties>

I then re-ran $ mvn clean wildfly:deploy and it worked.

Solution 16 - Eclipse

Both options work for me to resolved Source option 5 is no longer supported. Use 6 or later” on Maven compile

Open pom.xml file

Option1: add build tags

Option2: add properties tags

<project>
	<groupId>com.pluralsight</groupId>
	<artifactId>HelloWorld</artifactId>
	<version>1.0-SNAPSHOT</version>
	<modelVersion>4.0.0</modelVersion>
	<packaging>jar</packaging>
	
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.0</version>
				<configuration>
					<release>12</release>
				</configuration>
			</plugin>
		</plugins>
	</build>	
</project>

OR

<project>
	<groupId>com.pluralsight</groupId>
	<artifactId>HelloWorld</artifactId>
	<version>1.0-SNAPSHOT</version>
	<modelVersion>4.0.0</modelVersion>
	<packaging>jar</packaging>

	<properties>
		 <maven.compiler.source>1.6</maven.compiler.source>
		 <maven.compiler.target>1.6</maven.compiler.target>
    </properties> 
</project>

Solution 17 - Eclipse

This is a message from a newer javac, e.g.:

$ java -version
openjdk version "11" 2018-09-25

$ javac -source 1.5 -target 1.5 Test.java
error: Source option 5 is no longer supported. Use 6 or later.
error: Target option 1.5 is no longer supported. Use 1.6 or later.

So, apparently you're using a newer JDK version with a Maven version prior to 3.8.0 ("<source>/<target> ... NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6"). The maven-compiler-plugin:3.1 you use is from April 2013.

There are two possibilities:

  1. Update your Maven version to the latest (I'd recommend that)

  2. Setting the Java Version in Maven: > 2.2. Java 9 and Beyond > > ... > > lang-xml > <properties> > <maven.compiler.release>...</maven.compiler.release> > </properties> >

Solution 18 - Eclipse

I Solved it this way I faced the same challenge, what I did was to go to:

  1. File
  2. Project structure
  3. Module
  4. Changed compile SDK to 30 (Latest at the time)
  5. Build tools 30.0.3 (Latest)
  6. Source compatibility (1.8 Java 8)
  7. Target compatibility (1.8 Java 8)

Solution 19 - Eclipse

Change the

  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">

to

  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

enter image description here

Solution 20 - Eclipse

Set updated java version from build path as per you installed

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSUPARNA SOMANView Question on Stackoverflow
Solution 1 - EclipsekraftwerkView Answer on Stackoverflow
Solution 2 - EclipseMohsen AbasiView Answer on Stackoverflow
Solution 3 - EclipseSugat ShivsharanView Answer on Stackoverflow
Solution 4 - EclipsePrashant BiradarView Answer on Stackoverflow
Solution 5 - EclipseSUPARNA SOMANView Answer on Stackoverflow
Solution 6 - EclipseMauricio ToledoView Answer on Stackoverflow
Solution 7 - EclipseVinod PanthiView Answer on Stackoverflow
Solution 8 - EclipseShahid Hussain AbbasiView Answer on Stackoverflow
Solution 9 - Eclipseeclat_softView Answer on Stackoverflow
Solution 10 - EclipseAdelinView Answer on Stackoverflow
Solution 11 - EclipseahmnouiraView Answer on Stackoverflow
Solution 12 - EclipseSurya R PraveenView Answer on Stackoverflow
Solution 13 - EclipseDanView Answer on Stackoverflow
Solution 14 - EclipseAditi ManeView Answer on Stackoverflow
Solution 15 - EclipsedaktariView Answer on Stackoverflow
Solution 16 - EclipseIrina DanovichView Answer on Stackoverflow
Solution 17 - EclipseGerold BroserView Answer on Stackoverflow
Solution 18 - EclipsebensalcieView Answer on Stackoverflow
Solution 19 - EclipseTiago MediciView Answer on Stackoverflow
Solution 20 - EclipseChinmoyJView Answer on Stackoverflow