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

前端 未结 9 2502
谎友^
谎友^ 2021-02-01 00:54

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         


        
相关标签:
9条回答
  • 2021-02-01 01:31

    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>
    
    0 讨论(0)
  • 2021-02-01 01:32

    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>
    
    0 讨论(0)
  • 2021-02-01 01:36

    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
    
    0 讨论(0)
  • 2021-02-01 01:38

    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

    0 讨论(0)
  • 2021-02-01 01:38

    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)

    0 讨论(0)
  • 2021-02-01 01:45

    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>
    
    0 讨论(0)
提交回复
热议问题