## 普通maven项目配置编译器版本 参考maven官方文档 [Setting the `-source` and `-target` of the Java Compiler](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html) maven有2种方法设置编译JDK版本,比如配置为 Java 1.8 版本 1. 配置属性 ```xml [...] 1.8 1.8 [...] ``` 2. 直接配置插件 ```xml [...] [...] org.apache.maven.plugins maven-compiler-plugin 3.13.1 1.8 1.8 [...] [...] ``` > 如果在IDEA里正确设置了JDK版本,但不生效,右键 pom.xml ,选择Maven,点击 Reimport **source属性说明:** >The -source argument for the Java compiler. > >**NOTE:** Since 3.8.0 the default value has changed from 1.5 to 1.6. Since 3.9.0 the default value has changed from 1.6 to 1.7 >**Default value is**: `1.7`. >**User property is**: `maven.compiler.source`. **target属性说明:** >The -target argument for the Java compiler. > >**NOTE:** Since 3.8.0 the default value has changed from 1.5 to 1.6. Since 3.9.0 the default value has changed from 1.6 to 1.7 >**Default value is**: `1.7`. >**User property is**: `maven.compiler.target`. 从 maven-compiler-plugin3.8.0 开始,默认java编译器版本由1.5改为1.6了 从 maven-compiler-plugin3.9.0 开始,默认java编译器版本由1.6改为1.7了 更多属性说明参见[maven-compiler-plugin](https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html) ## SpringBoot项目配置maven编译器版本 如果引用做了父项目,可以如下配置 ```xml org.springframework.boot spring-boot-starter-parent 2.5.3 1.8 ``` 配置及其简单,因为在 spring-boot-starter-parent 已经配置好了 source、target 属性,只需用 java.version 覆盖默认值即可 ```xml [...] 1.8 ${java.version} ${java.version} [...] ```