最近在尝试着用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

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

335

被折叠的 条评论
为什么被折叠?



