问题现象

使用SpringBoot3.x,Idea中maven、项目均配置了JDK17+环境、,控制台执行打包命令mvn -Dmaven.test.skip=true -U clean install 报如下错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.12.0:compile (default-compile) on project chen-engine: Fatal error compiling: 无效记: --release -> [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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :chen-engine

解决方案

mac环境,windows环境方案一样,切换环境即可

针对我的电脑(JDK8 和JDK17共存),因为环境不匹配问题,idea配置只是针对当前项目的配置,当你打开控制台的时候,控制台用的是系统的环境配置(我的电脑默认启用的是JDK8),控制台如下命令检查你的当前系统环境mvn -v

>  mvn -v        
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /Users/chen/develop/gradle/apache-maven-3.6.1
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

此时将jdk8 切换至jdk17即可 执行命令jdk17(见下方JDK多环境配置)

> jdk17

再次执行打包命令mvn -Dmaven.test.skip=true -U clean install 即可

mac环境jdk17 命令配置

打开配置文件:sudo vim ~/.bash_profile,配置jdk17

JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home
JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
# 默认使用java8
export JAVA_HOME=$JAVA_8_HOME
export PATH="$JAVA_HOME:$PATH"

#alias jdk 配置此处,可以在控制台通过 jdk8、jdk17切换jdk版本呢
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk17="export JAVA_HOME=$JAVA_17_HOME"
Logo

一站式 AI 云服务平台

更多推荐