compilerVersion参数可用于指定插件将使用的编译器版本。但是,您还需要将fork设置为true才能正常工作。例如:
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <verbose>true</verbose> <fork>true</fork> <executable><!-- path-to-javac --></executable> <compilerVersion>1.3</compilerVersion> </configuration> </plugin> </plugins> [...] </build> [...] </project>
为避免硬编码可执行文件的文件系统路径,您可以使用属性。例如:
<executable>${JAVA_1_4_HOME}/bin/javac</executable>
然后每个开发人员在settings.xml中定义这个属性,或者设置一个环境变量,以便构建保持可移植性。
<settings> [...] <profiles> [...] <profile> <id>compiler</id> <properties> <JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME> </properties> </profile> </profiles> [...] <activeProfiles> <activeProfile>compiler</activeProfile> </activeProfiles> </settings>
如果您使用不同的 JDK 构建,您可能需要自定义jar 文件清单。