Site icon TestingDocs.com

How to fix Source option 5 is no longer supported. Use 7 or later

Introduction

When we create Maven projects using artifacts and try to run them, we sometimes get the following error: Source option 5 is no longer supported. Use 7 or later. In this post, we will see the steps involved in fixing the error in the Maven project.

The error (Source option 5 is no longer supported) is common when we create a Maven project from the old archetypes. In this case, we need to specify the source and target version to the Maven compiler. We can specify these properties in the Maven pom.xml file.

https://www.testingdocs.com/maven-project-from-archetype/

Error

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.025 s
------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:
3.1:testCompile (default-testCompile) on project AppiumProject: 
Compilation failure: Compilation failure: 
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.

 

Fix

The fix for the problem is to use the latest Java environment for the project: JDK 7 or Later version.

Identify the JDK version installed on your machine or the IDE workspace’s version. Update the project build path with the latest library settings.

 

Right-click Project properties >> Java Compiler.

Change the JDK compliance parameters from 1.5 -> 1.7 or above.

Click on the Execution Environments link and select the latest or suitable JDK above JDK 1.7

 

 

Click on theApply and Close button.

Maven POM.xml

Follow the below steps to avoid this error in the Maven project,

 

 

Examples

For example, to specify JDK 8 we can add the properties like the below to the POM.xml file:

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

JDK 14

Change the Java compiler and the project build path. After the changes specify the JDK version in the POM.xml Maven build file.

For example, specify the JDK 14 to the Maven pom.xml.

 

 

Sample pom.xml  file

Sample pom.xml file with JDK 14 version

 

<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testingdocs</groupId>
<artifactId>TestNGTutorials</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
   <maven.compiler.source>14</maven.compiler.source>
   <maven.compiler.target>14</maven.compiler.target>
</properties>
<dependencies>
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.0.0-alpha-7</version>
</dependency>
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-firefox-driver</artifactId>
   <version>4.0.0-alpha-7</version>
</dependency>
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-edge-driver</artifactId>
   <version>4.0.0-alpha-7</version>
</dependency>
<dependency>
   <groupId>org.testng</groupId>
   <artifactId>testng</artifactId>
   <version>6.8</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>3.0.0-M5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

 

Verify the fix

Run the Maven project. The error should be fixed now.

After changing the settings and adding the properties information to the pom.xml file. Verify by running the project. In Eclipse IDE, to build the project choose the option

Run As >> Maven Build

That’s it.

Maven Tutorial

Maven tutorial on this website:

https://www.testingdocs.com/apache-maven-tutorial/

Exit mobile version