JDK编译版本的错误

又有一个新项目接手,运行时正常的没有报错,但是编译却出错了。

这个项目是JDK11的项目,不知道为什么用Idea打包的时候却使用了JDK8。

问了一下AI。

在pom.xml中加上

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.10.1</version> <!-- JDK 11 推荐用 3.8+ 版本 --> <configuration> <!-- 统一为 JDK 11,消除版本不匹配警告 --> <release>11</release> <encoding>UTF-8</encoding> <!-- 可选:关闭严格泛型检查(避免额外报错) --> <compilerArgs> <arg>-Xlint:-unchecked</arg> </compilerArgs> </configuration> </plugin>

就可以正常编译了