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

Viewed 222489

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.

21 Answers

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>

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>

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]1

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>

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)

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.

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>  

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>

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

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
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>

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">

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

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

...

<properties>
   <maven.compiler.release>...</maven.compiler.release>
</properties>

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.

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.

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>

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)

Change the

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

to

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

enter image description here

Set updated java version from build path as per you installed

After so many years, happily seeing the same error ! :P

[ERROR] Source option 5 is no longer supported. Use 7 or later. [ERROR] Target option 5 is no longer supported. Use 7 or later.

pom.xml did not have any source or target declarations, so maven must have taken some archaic versions as default, rather than being clever enough to get it from the install JVM (which is currently on 18).

So, without knowing the original issue, I could also resolve it through the below snippet below. That declares a specific source and target version, which subpresses the problem.

<build>
   <plugins>
   <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>18</source>
            <target>18</target>
        </configuration>
    </plugin>
   </plugins>
   </build>
Related