M2E and having maven generated source folders as eclipse source folders

101,982

Solution 1

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:

Solution 2

Right-click the Error message:

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

in the Problems View and select Quick Fix and click Finish to select the default Update project configuration. This fixes it.

Solution 3

After switching to new versions of m2e/maven/apt,... i had builderrors because of the duplicated files, caused by the added buildpath by the buildhelper, so i needed to remove the "apt-generated"-Folders from the buildhelper.

To fix the Problem in Eclipse, not adding the "apt-generated"-folder via Update Maven Configuration in M2E, i've written a M2E Plugin to fix this problem. It adds the outputDirectories configured in the maven-apt-plugin to the buildpath of the Project.

https://apt-m2e.googlecode.com

Solution 4

In m2e 1.0 the handling of Maven plugins has changed. You might be lacking a specific m2e extension for your code generating plugin. Here is all the documentation I managed to find.

This bug report may also be relevant.

Solution 5

https://bugs.eclipse.org/bugs/show_bug.cgi?id=350081

request on CXF JIRA (see 1) to add lifecycle mappings in the cxf-codegen-plugin itself. This would require m2e 1.1 but I believe it is better approach than having connectors built outside of cxf project, assuming that lifecycle mapping API would change less frequently than cxf-codegen-plugin and cxf.

Share:
101,982
Michael Wiles
Author by

Michael Wiles

I'm a software developer living and working in Cape Town, South Africa. My specialities are Architecture, Java, JEE, JPA, Spring and Hibernate, GWT, GWTP and soon to be Android as well... I'm involved in building enterprise back-office applications, the front end and back end, currently in gwt.

Updated on January 13, 2022

Comments

  • Michael Wiles
    Michael Wiles over 2 years

    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.