M2E并将maven生成的源文件夹作为eclipse源文件夹

Mic*_*les 88 eclipse m2eclipse maven m2e

我在eclipse中有一个maven项目,并且有maven目标,运行注释处理器来生成代码.此代码的输出文件夹是target/generated-sources/apt.

为了让eclipse看到这个生成的代码,我需要将target/generated-sources/apt作为源文件夹添加到eclipse项目中.

但是,这会导致出现"Maven配置问题"类型的错误

项目配置与pom.xml不是最新的.运行项目配置更新

我想我明白为什么会这样,因为eclipse有一组不同的源文件夹到maven的集合.但我需要这个不同的设置,因为我需要eclipse才能看到生成的源文件夹...

在构建纯maven时,这些源文件夹将由maven包含在构建中.

顺便说一句,我已升级到maven eclipse插件的官方eclipse版本,m2e 1.0 - 曾经是m2eclipse.在我不得不回到旧的m2eclipse版本之前,我想看看我是否可以使用m2e插件找到解决方案/解决方案.

Mic*_*l-O 103

您需要使用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>
Run Code Online (Sandbox Code Playgroud)

您还需要:

  • 当在Eclipse中安装`m2e connector for build-helper-maven-plugin`时,这个解决方案很有用 (4认同)
  • 使用Kepler,我还必须为build helper maven插件安装m2e连接器.(只需在eclipse的maven pom编辑器中打开你的pom,然后点击顶部的红色链接). (2认同)

小智 80

右键单击错误消息:

使用pom.xml运行项目配置更新时项目配置不是最新的

在Problems View中,选择Quick Fix并单击Finish选择默认的Update project配置.这解决了它.

  • @NielsBasjes这不是公认的答案,因为它根本没用.当您在Eclipse中向构建路径添加内容时,这意味着您不再与POM同步,因此警告.更新项目配置只会删除额外的构建路径条目,这是最初的问题. (13认同)