IDEA-Maven编译报错:不再支持源选项 5。请使用 6 或更高版本

项目场景:

IDEA版本2020.1,Maven版本3.6.3
初学者,IDEA创建一个简单的Java类型的Maven项目,利用Junit4.13测试Demo【pom.xml已添加junit依赖包】


问题描述:

编译报错:不再支持源选项 5。请使用 6 或更高版本


原因分析:

JDK版本问题


解决方案:

<一>在项目的pom.xml文件中指定jdk版本,分别是UTF-8编码的指定和JDK版本,此处博主用的是JDK11.0.6版本。

   <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

<二>在Maven-conf里的settings.xml文件中指定jdk版本

<profile>  
     <id>jdk-10</id>  
     <activation>  
         <activeByDefault>true</activeByDefault>  
         <jdk>10</jdk>  
     </activation>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>10</maven.compiler.source>  
         <maven.compiler.target>10</maven.compiler.target>   
     </properties>   
</profile>

<三>在Maven-conf里的settings.xml文件和pom.xml文件中都指定jdk版本
setting.xml:

   <profile>
        <id>custom-compiler</id>
        <properties>
          <JAVA8_HOME>D:\DevelopmentTools\Java\jdk-11.0.6</JAVA8_HOME>
        </properties>
    </profile>
    <!--激活-->
   <activeProfiles>
    <activeProfile>custom-compiler</activeProfile>-->
  </activeProfiles>

pom.xml:

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <executable>${JAVA8_HOME}/bin/javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值