LoginSignup
10
9

More than 5 years have passed since last update.

mavenやantでEclipseのコンパイラーを使う

Last updated at Posted at 2014-01-23

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
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9