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

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

问题描述

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



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



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


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


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



当构建纯Maven时,这些源文件夹将包括在构建中,由maven。



btw,我已经升级到官方eclipse版本的maven eclipse插件,m2e 1.0 - 以前是什么m2eclipse。我想看看是否可以找到一个解决方案/解决方案与m2e插件,我必须回到旧的m2eclipse版本。

解决方案

您需要使用构建助手来附加源目录-plugin



像这样:

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> build-helper-maven-plugin< / artifactId>
<执行>
< 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>

您还需要:




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.

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.

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

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

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...

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

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.

解决方案

You need to attach the source directory with the build-helper-plugin.

Like so:

 <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>

You will also need to:

  • Install the "Apt M2E Connector" from the Eclipse Marketplace. To do so click the error in the Overview tab of your pom.xml and select "Discover".
  • Ensure there are no plugin execution filters for the build-helper-maven-plugin (see http://wiki.eclipse.org/M2E_plugin_execution_not_covered)

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

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