메이븐에서 이클립스 컴파일러 사용하기

이클립스가 자체 컴파일러를 가지고 있다는 것을 몰랐다. 자바 컴파일러를 불러쓴다고 생각하고 있었는데, 이클립스 컴파일러(ecj)는 오라클의 자바 컴파일러(javac)와 결과물이 꽤 달랐다. 나는 javac를  써주고 싶지만, 사정상…  찾아보았다.

의외로 찾는데 오래걸렸다. maven에서 이클립스 컴파일러를 쓸 수 있게 해주는 플러그인이 있고, 버전 지정도 할 수 있다.

(원래 포스트에서는 plexus-compiler-eclipse를 사용했으나,  tycho 라는 새버전이 있었다. plexus로 해결안되던 문제가 있었는데, tycho가 해결해주었다. 어쨌든 tycho까지 찾는 건 더 많은 시간이 걸렸다.)

<build>

...

<plugins>
<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <debug>true</debug>
          <compilerId>jdt</compilerId>
          <source>1.7</source>
          <target>1.7</target>
          <!--compilerArgument>-warn:unused,raw,unavoidableGenericProblems</compilerArgument-->
          <compilerArgument>-warn:none</compilerArgument>
          <compilerArguments>
            <properties>${project.basedir}/pom.pref</properties>
          </compilerArguments>
          <showDeprecation>true</showDeprecation>
        </configuration>
        <dependencies>
         <dependency>
           <groupId>org.eclipse.tycho</groupId>
           <artifactId>tycho-compiler-jdt</artifactId>
           <version>0.23.0</version>
         </dependency>
        </dependencies>
</plugin>

컴파일러에게 옵션을 주려면 <properties>${project.basedir}/pom.pref</properties></pre> 처럼 별도 파일로 설정해주어야 하고,  설정파일은 이렇게 구성한다

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve

사용가능한 옵션들은 요기서 찾을 수 있다.