一. 报错部分代码如下:
[INFO] --- maven-compiler-plugin:3.11.0:compile (default-compile) @ radiometer-management ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 2 source files with javac [debug release 1.8] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.537 s
[INFO] Finished at: 2023-05-30T16:50:46+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project radiometer-management: 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
二. 报错原因排查
首先百度过之后知道要核查jdk版本。
1.pom.xml引用JDK版本。
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>radiometer-management</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>radiometer-management</name>
<description>radiometer-management</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oscar</groupId>
<artifactId>oscarJDBC16</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/oscarJDBC16.jar</systemPath>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
</project>
2.Maven引用的JDK版本
3.Maven使用的Java版本
三、发现项目的pom.xml文件里缺少插件的引用
加入以下代码。注:source和target要和引用的JDK统一版本,不然会报错。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
四、重新编译项目,还是报错
主要错误如下所示:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project radiometer-management: Fatal error compiling: 无效的标记: --release -> [Help 1]
淦!设置了一圈怎么报错还是不变,这时候已经过去2小时,快崩溃了。期间经历了clean、reload,依然报同一个错误。网上的各种方法都试了。版本的统一也检查了800遍就是运行不成功。最后怀疑是不是某个版本号太高了,和JDK8不兼容,把
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
里的3.1.0改成了2.7.3。点击reload project。重新运行项目,希望这次不会出错了呀!
五、终于
还是报错!!!只不过这次换了个错误,表示真的是因为前面引用的版本号太高了导致上一个错误。新的错误是什么呢?
org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
?这是什么鬼,让我们翻译一下:
org/springframework/boot/maven/RepackageMojo是由较新版本的Java Runtime(类文件版本61.0)编译的,该版本的Java运行时只能识别52.0以下的类文件版本
没办法了,距离成功只差一步,继续善用网络。先是查询了错误中提到的类文件版本61.0,发现一个对应关系如下表:
49 = Java 5
50 = Java 6
51 = Java 7
52 = Java 8
53 = Java 9
54 = Java 10
55 = Java 11
56 = Java 12
57 = Java 13
58 = Java 14
…
由此可以推断出编译时用到的类文件版本61对应的是Java 17,可是系统中只识别到了Java8,可是我也没设置过Java17呀,为什么用这个版本编译?
终于发现是因为之前用的spring-boot版本太高了,也需要修改。文章来源:https://www.toymoban.com/news/detail-594779.html
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.3.RELEASE</version>
</plugin>
将3.1.0降为2.3.3.RELEASE。点击右侧Maven—Lifecycle—clean。
右击项目,选择Maven—Reload project。等待下载2.3.3版本。完成后重新运行项目——成功!!!
文章来源地址https://www.toymoban.com/news/detail-594779.html
到了这里,关于SpringBoot项目编译报错——Fatal error compiling:无效的标记: --release -> [Help 1]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!