Tho*_*ung 16 java eclipse maven-2 annotations javac
为Java 6注释处理器设置eclipse项目编译器配置的最佳方法是什么?
我的解决方案是手动设置org.eclipse.jdt.apt.core.prefs和factorypath文件.这有点麻烦:
(org.eclipse.jdt.apt.genSrcDir属性org.eclipse.jdt.apt.core.prefs)一个问题是eclipse生成的源将使用maven编译.只有maven clean compile可靠,因为它删除了eclipse生成的源文件.(Eclipse和javac生成的源文件可能不同步.)
有没有更好的解决方案来配置maven没有eclipse生成的源文件在maven源路径?
<project>
<properties>
<eclipse.generated.src>${project.build.directory}/eclipse</eclipse.generated.src>
</properties>
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals> <goal>add-source</goal> </goals>
<configuration>
<sources>
<source>${eclipse.generated.src}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalConfig>
<file> <name>.factorypath</name>
<content><![CDATA[<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/processor/processor.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
]]> </content>
</file>
<file>
<name>.settings/org.eclipse.jdt.apt.core.prefs</name>
<content><![CDATA[
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipse.generated.src}
org.eclipse.jdt.apt.reconcileEnabled=true
]]> </content>
</file>
</additionalConfig>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
更新:您可以尝试使用apt-maven-plugin.它目前提供三个目标:
您可以将目标配置为作为构建的一部分运行,如下所示:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
<goal>test-process</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
Run Code Online (Sandbox Code Playgroud)
默认情况下,输出目录设置为${project.build.directory}/generated-sources/apt,
对于编译器插件有一个开放的Jira来添加对Java 6的APT支持,如果你希望在将来的版本中看到它,你可以去投票.
| 归档时间: |
|
| 查看次数: |
11263 次 |
| 最近记录: |