maven打包java11出错 Fatal error compiling: 错误: 无效的目标发行版:1.11 -> [Help 1]解决方案

本文解决IDEA Maven打包SpringBoot项目时因Java11目标发行版导致的错误,通过修改pom.xml及setting.xml配置,成功实现Java11环境下项目编译。

最近在尝试着用java11编译项目,博主在用idea Maven打包springboot的一个项目时发生如下错误:

 ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.187 s
[INFO] Finished at: 2019-06-27T10:15:05+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project provider-ticket: Fatal error compiling: 错误: 无效的目标发行版:1.11 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

上网找了好多博客也没有解决问题,大多数博客都让pom.xml加上如下参数

<properties>
    <java.version>11</java.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

受到启发,尝试修改了一下maven的setting.xml文件

<profile>    
      <id>jdk-11</id>    
      <activation>    
          <activeByDefault>true</activeByDefault>    
           <jdk>11</jdk>    
      </activation>    
    <properties>    
         <maven.compiler.source>11</maven.compiler.source>    
         <maven.compiler.target>11</maven.compiler.target>    
         <maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>    
     </properties>    
     </profile>

然后重启idea打包如下:

博主试了下 好想与maven版本无关 我用了 3.5.4 和 3.6.1都是可以的 希望对大家有所帮助,如果打包过程中出现test的错误,

可使用maven命令 跳过

mvn clean package -DskipTests

用插件的话 可以点击⚡图标 ,跳过test 

希望对大家有所帮助

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值