ERROR Source option 1.5 is no longer supported. Use 1.6 or later

后端 未结 10 966
[愿得一人]
[愿得一人] 2020-12-24 04:32

It all happens when I was trying to build a springboot application by ./mvnw clean install

When I first run the install command, it runs into followin

相关标签:
10条回答
  • 2020-12-24 04:51

    You need to set JDK 1.5 to your project and also all dependent project or jar file should also compiled with JDK 1.5

    0 讨论(0)
  • 2020-12-24 04:54

    I think this means that

    • You are using JDK9 or later
    • Your project uses maven-compiler-plugin with an old version which defaults to Java 5.

    You have three options to solve this

    1. Downgrade to JDK7 or JDK8 (meh)
    2. Use maven-compiler-plugin version or later, because

      NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6 See https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#target

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
      </plugin>
      
    3. Indicate to the maven-compiler-plugin to use source level 6 and target 6 (or later).

      Best practice recommended by https://maven.apache.org/plugins/maven-compiler-plugin/

      Also note that at present the default source setting is 1.6 and the default target setting is 1.6, independently of the JDK you run Maven with. You are highly encouraged to change these defaults by setting source and target as described in Setting the -source and -target of the Java Compiler.

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
          </configuration>
      </plugin>
      

      or use

      <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
      </properties>
      
    0 讨论(0)
  • 2020-12-24 04:56

    This worked for me!!!!

    <?xml version="1.0" encoding="UTF-8"?>
    
    <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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>academy.learnprogramming</groupId>
        <artifactId>hello-maven</artifactId>
        <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
    
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <target>10</target>
                    <source>10</source>
                    <release>10</release>
                </configuration>
    
            </plugin>
        </plugins>
    </build>
    </project>
    
    0 讨论(0)
  • 2020-12-24 04:58

    I got this error: "Source option 5 is no longer supported. Use 6 or later" after I changed the pom.xml

    <java.version>7</java.version>
    

    to

    <java.version>11</java.version>
    

    Later to realise the property was used with a dash insteal of a dot:

      <source>${java-version}</source>
      <target>${java-version}</target>
    

    (swearings), I replaced the dot with a dash and the error went away:

    <java-version>11</javaversion>
    
    0 讨论(0)
  • 2020-12-24 05:02

    This error might be also for plugin versions. You can fix it in the .POM file like the followings:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
  • 2020-12-24 05:03

    You can specify maven source/target version by adding these properties to your pom.xml file

    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    
    0 讨论(0)
提交回复
热议问题