一. 報(bào)錯(cuò)部分代碼如下:
[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: 無(wú)效的標(biāo)記: --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
二. 報(bào)錯(cuò)原因排查
首先百度過(guò)之后知道要核查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版本
三、發(fā)現(xiàn)項(xiàng)目的pom.xml文件里缺少插件的引用
加入以下代碼。注:source和target要和引用的JDK統(tǒng)一版本,不然會(huì)報(bào)錯(cuò)。
<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>
四、重新編譯項(xiàng)目,還是報(bào)錯(cuò)
主要錯(cuò)誤如下所示:
[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: 無(wú)效的標(biāo)記: --release -> [Help 1]
淦!設(shè)置了一圈怎么報(bào)錯(cuò)還是不變,這時(shí)候已經(jīng)過(guò)去2小時(shí),快崩潰了。期間經(jīng)歷了clean、reload,依然報(bào)同一個(gè)錯(cuò)誤。網(wǎng)上的各種方法都試了。版本的統(tǒng)一也檢查了800遍就是運(yùn)行不成功。最后懷疑是不是某個(gè)版本號(hào)太高了,和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。點(diǎn)擊reload project。重新運(yùn)行項(xiàng)目,希望這次不會(huì)出錯(cuò)了呀!
五、終于
還是報(bào)錯(cuò)?。?!只不過(guò)這次換了個(gè)錯(cuò)誤,表示真的是因?yàn)榍懊嬉玫陌姹咎?hào)太高了導(dǎo)致上一個(gè)錯(cuò)誤。新的錯(cuò)誤是什么呢?
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運(yùn)行時(shí)只能識(shí)別52.0以下的類文件版本
沒(méi)辦法了,距離成功只差一步,繼續(xù)善用網(wǎng)絡(luò)。先是查詢了錯(cuò)誤中提到的類文件版本61.0,發(fā)現(xiàn)一個(gè)對(duì)應(yīng)關(guān)系如下表:
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
…
由此可以推斷出編譯時(shí)用到的類文件版本61對(duì)應(yīng)的是Java 17,可是系統(tǒng)中只識(shí)別到了Java8,可是我也沒(méi)設(shè)置過(guò)Java17呀,為什么用這個(gè)版本編譯?
終于發(fā)現(xiàn)是因?yàn)橹坝玫膕pring-boot版本太高了,也需要修改。文章來(lái)源:http://www.zghlxwxcb.cn/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。點(diǎn)擊右側(cè)Maven—Lifecycle—clean。
右擊項(xiàng)目,選擇Maven—Reload project。等待下載2.3.3版本。完成后重新運(yùn)行項(xiàng)目——成功?。?!文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-594779.html
到了這里,關(guān)于SpringBoot項(xiàng)目編譯報(bào)錯(cuò)——Fatal error compiling:無(wú)效的標(biāo)記: --release -> [Help 1]的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!