mavenの場合
<compilerId>とplexus-compiler-eclipseがポイントになります。
forceJavacCompilerUseなど相反するオプションを付けては駄目です。
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<verbose>true</verbose>
<source>1.7</source>
<target>1.7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
以下のプロジェクトは、Eclipseコンパイラーではコンパイルエラーにはならず、javacではコンパイルエラーになるサンプルです。
https://github.com/ko2ic/spike-maven-with-eclipse-compiler
antの場合
コンパイルタスクの前にJDTCompilerAdapterを指定する
build.xml
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
JDTCompilerAdapterがあるjarは、以下のように探してます。
grepEclipseCompiler.sh
# !/bin/sh
find . -name "*.jar" | while read jar
do
count=$(jar tf $jar | grep jdtCompilerAdapter | wc -l)
if [ $count -gt 0 ];then
echo $jar
fi
done
$ cd eclipse/plugins
$ sudo ./grepEclipseCompiler.sh
./org.eclipse.jdt.core.source_3.9.1.v20130905-0837.jar
./org.eclipse.jdt.core_3.9.1.v20130905-0837.jar