Maven Compile 編譯報錯

首先在 IDEA 中使用 Maven 的外掛中的 Lifecycle 進行 compile 指令,發現報錯:

Failed to execute goal org。apache。maven。plugins:maven-compiler-plugin:3。1:compile (default-compile) on project ssm-utils: Fatal error compiling

然後命令列執行

mvn compile

得到更詳細的報錯資訊如下

Failed to execute goal org。apache。maven。plugins:maven-compiler-plugin:3。1:compile (default-compile) on project ssm-utils: Fatal error compiling: 錯誤: 無效的目標發行版:1。11

回到 pom。xml 的檔案中檢視配置:

<!—— 指定編碼及版本 ——> UTF-8 UTF-8 1。11 1。11 1。11 5。1。5。RELEASE 5。1。5。RELEASE 3。5。1

發現

的版本號不對,應該為 11;而且 Java 8 到 13 的版本號填寫方式為

1。8, 1。9, 1。10, 10, 11, 12, 13

因此修改配置:

<!—— 指定編碼及版本 ——> UTF-8 UTF-8 1。11 11 11 5。1。5。RELEASE 5。1。5。RELEASE 3。5。1

然後執行

mvn compile

成功編譯。

或者在

pom。xml

的 project 標籤內的最後加上:

。。。 org。apache。maven。plugins maven-compiler-plugin 3。6。1 11 11 ${maven。compiler。encoding}

這樣也可以保證 Maven 外掛的編譯的 JDK 版本號正確。

想了解更多,歡迎關注我的微信公眾號:Renda_Zhang