在项目的pom.xml中加入:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA8_HOME}/bin/javac</executable>
</configuration>
</plugin>
</plugins>
</build>
然后去修改C:\Users\Administrator\.m2中的settings.xml文件(如果项目配置了maven的settings.xml,则去改maven的)
<profiles>
<profile>
<id>custom1-compiler</id>
<properties> <JAVA8_HOME>D:\Java\jdk1.8.0_161</JAVA8_HOME> </properties>
</profile>
</profiles> //激活上面的配置 和上面的ID对应,就是激活对应的配置
<activeProfiles>
<activeProfile>custom1-compiler</activeProfile>
<activeProfile>custom-compiler</activeProfile>
</activeProfiles>