我在 Eclipse 中有一个 Maven 项目,并且有运行注释处理器来生成代码的 Maven 目标。此代码的输出文件夹是 target/generated-sources/apt
。
为了让 Eclipse 看到生成的代码,我需要将 target/generated-sources/apt
作为源文件夹添加到 Eclipse 项目中。
但是,这会导致出现“Maven 配置问题”类型的错误
Project configuration is not up-to-date with
pom.xml
. Run project configuration update
我想我明白为什么会出现这种情况,因为 Eclipse 有一组与 Maven 不同的源文件夹。但我需要这个不同的集合,因为我需要 Eclipse 才能看到生成的
源文件夹...
当进行纯 Maven 构建时,这些源文件夹将由 Maven 包含在构建中。
顺便说一句,我已经升级到 Maven Eclipse 插件的官方 Eclipse 版本 m2e 1.0 - 以前是 m2eclipse。我想看看在必须返回到旧的 m2eclipse 版本之前是否可以使用 m2e 插件找到解决方案/解决方案。
最佳答案
您需要将源目录附加到 build-helper-plugin .
像这样:
<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/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
您还需要:
- 从 Eclipse Marketplace 安装“Apt M2E Connector”。 为此,请单击 pom.xml 的“概述”选项卡中的错误并选择“发现”。
- 确保 build-helper-maven-plugin 没有插件执行过滤器(请参阅 https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html )
关于eclipse - M2E 并让 Maven 生成源文件夹作为 Eclipse 源文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7160006/