目前,对于在eclipse中使用mapstruct的每个项目,我都要去:
配置构建路径> Java编译器>注释处理>工厂路径
并选中“使用项目特定设置”并配置工厂路径以便每次手动使用mapstruct处理器jar。
短语“使用项目特定设置”类型暗示了某个地方的全局设置,但我无法在“首选项”下找到类似这样的内容。
我可以在某些地方配置注释处理的默认行为吗?
答案 0 :(得分:0)
查看对MapStruct的Eclipse支持。
您需要将m2e_apt
添加到您的媒体资源中。
<properties>
<!-- automatically run annotation processors within the incremental compilation -->
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
</properties>
并确保您已正确设置maven编译器。
我们建议使用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>
答案 1 :(得分:0)
我遵循了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:
<classpathentry kind="src" output="target/classes" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>