有个项目是基于jdk 7的,但是目前的项目都是基于jdk 17,查看了一下maven官方文档,可以使用ToolChains(https://maven.apache.org/guides/mini/guide-using-toolchains.html)进行多版本jdk编译。
项目的pom.xml增加toolchains编译配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
创建toolchains.xml文件,放在目录:${user.home}/.m2/。或者指定参数:--global-toolchains
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>oracle</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
</jdkHome>
</configuration>
</toolchain>
</toolchains>