方法一:使用配置指定使用的JDK版本(官方推荐)
只需要在父项目的pom.xml中添加,然后reimport即可
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>方法二:添加build插件
在父项目的pom.xml文件中添加maven-compiler-plugin插件,并且指定编译时使用的JDK版本
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>方法三:在maven的配置文件中配置profiles(一劳永逸)
打开maven配置文件settings.xml,在profiles标签里添加一个profile子标签进行配置
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>我比较倾向于选择第一种方式,相比较其他两种方式,有点是配置简单,缺点是每个项目都需要配置。如果考虑到协作的话,其实第三种一劳永逸的法子也只是对于在你的机器上而言,所以推荐第一种