且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-10-14 23:26:53

您需要使用构建助手来附加源目录-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)