自Maven 3.0起,默认的Java编译器是javax.tools.JavaCompiler
。如果希望插件使用javac
,则必须设置插件选项forceJavacCompilerUse
默认的source
配置是1.5
,默认的target
配置是1.5
,这与Maven运行的JDK无关。
Compiler插件有两个goal:
compiler:compile
compiler:testCompile
mvn compile
mvn test-compile
配置
指定编译使用的JDK路径,指定编译器版本
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
使用环境变量指定路径
<executable>${JAVA_1_4_HOME}/bin/javac</executable>