M2E 并让 maven 生成源文件夹作为 Eclipse 源文件夹 [英] M2E and having maven generated source folders as eclipse source folders

查看:47
本文介绍了M2E 并让 maven 生成源文件夹作为 Eclipse 源文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a maven project in eclipse and have maven goals that run annotation processors to generate code. The output folder for this code is target/generated-sources/apt.

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

In order for eclipse to see this generated code I need to add target/generated-sources/apt as a source folder to the eclipse project.

然而,这会导致出现Maven Configuration Problem"类型的错误

However, this causes there to be an error of type "Maven Configuration Problem" saying

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

Project configuration is not up-to-date with pom.xml. Run project configuration update

我想我明白为什么会出现这种情况,因为 eclipse 的源文件夹集与 maven 的集不同.但我需要这个不同的集合,因为我需要 eclipse 才能看到生成的源文件夹...

I think I understand why this is the case as eclipse has a different set of source folders to maven's set. But I need this different set, as I need eclipse to be able to see the generated source folders...

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

When doing a pure maven built, these source folders will be included in the build, by maven.

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

btw, I have upgraded to the official eclipse release of the maven eclipse plugin, m2e 1.0 - what used to be m2eclipse. I'd like to see if I can find a work around/solution to this with the m2e plugin before I have to go back to the old m2eclipse version.

推荐答案

您需要使用 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>

您还需要:

这篇关于M2E 并让 maven 生成源文件夹作为 Eclipse 源文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆