问题:

解决步骤:
1.修改maven的配置文件settings.xml
- 找到profiles标签,在其内添加以下内容
- 这里我的JDK版本是11,JDK8将 11 换成 1.8 即可

<profile>
<id>jdk-11</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>11</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<Maven.compiler.source>11</Maven.compiler.source>
<Maven.compiler.target>11</Maven.compiler.target>
<Maven.compiler.compilerVersion>11</Maven.compiler.compilerVersion>
</properties>
</profile>
2.在项目的pom.xml中添加编译插件
- 在plugins标签中添加蓝色框内容
- 红色框为编译JDK版本,换成你使用的版本即可

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
结果:

|