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

扶醉桌前 提交于 2020-08-01 01:25:12

问题


I am getting the following error or $ 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. Can someone help me in resolving this issue? Thanks in advance


回答1:


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>



回答2:


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




回答3:


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)




回答4:


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.




回答5:


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



回答6:


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



回答7:


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>



回答8:


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>


来源:https://stackoverflow.com/questions/53034953/error-source-option-5-is-no-longer-supported-use-6-or-later-on-maven-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!