[英]In Eclipse, is it possible to set annotation processing and factory path by default?
目前,对于在 eclipse 中使用 mapstruct 的每个项目,我必须去:
配置构建路径 > Java 编译器 > 注释处理 > 工厂路径
并选中“使用项目特定设置”并配置工厂路径以每次手动使用 mapstruct 处理器 jar。
“使用特定于项目的设置”这句话暗示了某处的全局设置,但我在首选项下找不到任何类似的东西。
有什么地方可以配置注释处理的默认行为吗?
查看Eclipse对 MapStruct 的支持。
您需要将m2e_apt
添加到您的属性中。
<properties>
<!-- automatically run annotation processors within the incremental compilation -->
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
</properties>
并确保您已正确设置 maven-compiler。
我们建议使用 maven-compiler-plugin 的annotationProcessorPaths
选项(使用它,不会泄漏编译路径上的 mapstruct 处理器)。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source> <!-- or higher, depending on your project -->
<target>1.6</target> <!-- or higher, depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
我遵循了 Filip 的建议,但是一旦将项目导入到 Eclipse 工作区中,我就无法让 Eclipse 添加必要的类路径。 我在 pom.xml 中添加了 build-helper-maven-plugin 以帮助 Eclipse 添加所需的类路径:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations/</source>
</sources>
</configuration>
</execution>
</executions>
这导致 .classpath 文件中出现所需的类路径:
<classpathentry kind="src" output="target/classes" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.