95

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Michael Wiles
  • 20,902
  • 18
  • 71
  • 101

12 Answers12

110

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:

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • 4
    this solution works great when the `m2e connector for build-helper-maven-plugin` is installed in Eclipse – Brad Cupit Jan 11 '12 at 19:13
  • Doesn't work for me. Can you elaborate on the build-helper-plugin setup? – Kevin Wong Feb 27 '12 at 19:42
  • org.codehaus.mojo build-helper-maven-plugin add-source generate-sources add-source ${project.build.directory}/generated-sources/java/ ${project.build.directory}/jaxws/wsimport/java – Kevin Wong Feb 28 '12 at 16:35
  • Perhaps I need to install that m2e connector for build-helper-maven-plugin, which I found no obvious way to do. Can anyone point me at installation instructions for that connector? – Kevin Wong Feb 28 '12 at 17:11
  • Yes, you will need that. It's available on the m2eclipse market place. Worked for me perfectly. – Michael-O Feb 28 '12 at 20:52
  • Okay, worked for me now. I've updated the answer accordingly. – Kevin Wong Apr 25 '12 at 03:27
  • just a note for others (like me), `plugin` element is in `/project/build/plugins` and NOT in `/project/build/pluginManagement/plugins` – Betlista Sep 10 '12 at 09:22
  • 2
    With Kepler, I had to also install m2e connector for build helper maven plugin. (Just open your pom inside the maven pom editor of eclipse and click on the red link at the top). – Snicolas Sep 05 '13 at 05:59
  • The Apt M2E Connector is not required, but the org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml plugin, available via Window -> Preferences -> Maven -> Discovery. If "Open Catalog" fails, go to the URL in a browser, download the JAR, open it and copy the lifeCycleMappingMetaData as part of your pluginManaagement in your pom.xml. – koppor Nov 27 '13 at 17:55
  • Now I am being told that I have a duplicate class (by the maven-compiler-plugin) since the class is already being compiled by the maven-jaxb-plugin, which generated java classed based on an xsd file representing XML configuration structure. – abdelrahman-sinno May 22 '15 at 14:02
  • Tell XJC not to compile the code but generate only. – Michael-O May 22 '15 at 14:27
  • Repository of "Apt M2E Connector" does not exists anymore. Alternatives? – Deviling Master Feb 21 '17 at 11:00
  • Same. the link to build-helper-maven is broken. It maybe should be replaced by this [one](http://www.mojohaus.org/build-helper-maven-plugin/usage.html) – João Rebelo Mar 28 '18 at 08:20
  • 1
    As far as I can tell, as of `build-helper-maven-plugin` with `` specified as `3.2.0` (the latest as of writing), there is no need to use Apt M2E Connector. Currently working on Eclipse IDE 2020-06, using embedded Maven 3.6.3 in Eclipse, and our problems with source folder having exclusions (\*\*) went away after attempting to add the source folders' directory paths in. Now, the inclusions all have (\*\*/\*.java) in them. – tom_mai78101 Aug 06 '20 at 21:48
80

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.

Aaron
  • 55,518
  • 11
  • 116
  • 132
peter
  • 841
  • 1
  • 6
  • 2
  • 1
    This works for me too. Why isn't this the accepted answer? Seems the accepted answer does too much. – Niels Basjes Mar 27 '12 at 21:06
  • 14
    @NielsBasjes this isn't the accepted answer because it simply isn't helpful. When you add something to the build path in Eclipse, that means you are no longer in sync with the POM, hence the warning. Updating the project configuration simply removes the extra build path entry, which was the initial problem to begin with. – Phil Oct 20 '13 at 22:07
4

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

Stefan Wo
  • 49
  • 1
  • 1
  • 1
    unfortunately @Stefan Wo your plugin page/repo is now 404 at googlecode.com; would you mind updating it, as well as the Eclipse Marketplace entry? see https://marketplace.eclipse.org/content/apt-m2e-connector – maxxyme Sep 28 '17 at 13:01
3

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.

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
  • i guess m2e is new and has lots of outstanding development – Michael Wiles Aug 26 '11 at 09:04
  • 2
    I believe the problem is that just applying Maven plugins to m2eclipse projects, as m2eclipse used to do, just happened to work most of the time, but wasn't guaranteed to always do the right thing. The new approach is potentially more solid, but requires that many Maven plugins have an m2e counterpart. – Nicola Musatti Aug 26 '11 at 09:15
2

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.

0

You can also use the buildhelper m2e connector available in the discovery catalog. I'm using Eclipse 3.7

Cédric Vidal
  • 153
  • 1
  • 5
0

Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 1

mvn archetype:generate \
   -DarchetypeGroupId=org.codehaus.mojo \
   -DarchetypeArtifactId=gwt-maven-plugin \
   -DarchetypeVersion=2.5.0

mvn clean install

work perfectly.

But in eclipse I have the same error on Asinc class.

Just press F5 on project. Fix this problem.

burtsevyg
  • 3,851
  • 2
  • 29
  • 44
0

This was what I found that worked good using spring 3.1.1 which does have the 3.0.6 version as well in it. Once I got the plugins setup and put into the correct area of the pom and included the argline and endorseddirs to have the java sources put out into the target/generated-sources/cxf folder then maven generated the sources ok.

....

 <properties>...

   <dependencyManagement>
      <dependencies>.....
   </dependencyManagement>

<dependencies>
   <dependency>....

</dependencies>



<!-- *************************** Build process ************************************* -->
<build>
    <finalName>eSurety</finalName>
    <plugins>
        <!-- Force Java 6 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <!-- Deployent on AS from console
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>${version.jboss.as.maven.plugin}</version>
        </plugin>
        -->

        <!-- wildbill added tomcat plugin -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>              
        </plugin>

        <!-- Surefire plugin before 2.9 version is buggy. No need to declare here,
              it's being referenced below w/ the version
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
        </plugin>
        -->

        <!-- developer added these -->   
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArguments>
                    <endorseddirs>target/generated-sources/cxf</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
            <configuration>
                <forkMode>once</forkMode>
                <argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine>
            </configuration>
        </plugin>           
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArguments>
                    <endorseddirs>target/generated-sources/cxf</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <forkMode>once</forkMode>
                <argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine>
            </configuration>
        </plugin>                       
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>                       
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>javax.xml.bind</groupId>
                        <artifactId>jaxb-api</artifactId>
                        <version>2.2</version>
                    </artifactItem>
                    <artifactItem>
                        <groupId>javax.xml.ws</groupId>
                        <artifactId>jaxws-api</artifactId>
                        <version>2.2</version>
                    </artifactItem>
                </artifactItems>
                <outputDirectory>target/generated-sources/cxf</outputDirectory>
            </configuration>                      
        </plugin>                                                 
    </plugins>
</build>



<!-- *********************** Profiles ************************************ -->
<profiles>
    <profile>
        <!-- When built in OpenShift the 'openshift' profile will be 
            used when invoking mvn. -->
        <!-- Use this profile for any OpenShift specific customization 
            your app will need. -->
        <!-- By default that is to put the resulting archive into the 
            'deployments' folder. -->
        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
        <id>projName</id>
        <build>
            <plugins>                                                   
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>2.5.2</version>                        
                    <executions>
                        <execution>
                            <id>process-sources</id>
                            <phase>generate-sources</phase>                                                                                               
                            <configuration>
                                <fork>once</fork>
                                <additionalJvmArgs>-Djava.endorsed.dirs=target/generated-sources/cxf</additionalJvmArgs>                                          
                            </configuration>
                            <goals>                             
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>                       
                    <dependencies>
                        <dependency>
                           <groupId>com.sun.xml.bind</groupId>
                           <artifactId>jaxb-impl</artifactId>
                           <version>2.2</version>
                        </dependency>
                        <dependency>
                           <groupId>com.sun.xml.bind</groupId>
                           <artifactId>jaxb-xjc</artifactId>
                           <version>2.2</version>
                        </dependency>
                     </dependencies>
                </plugin>

                <!-- Actual war created in default target dir -->
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>                                               
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

If your wsdl folder is in ${basedir}/src/main/resources it'll find it automatically

Hope this helps! ~wildbill

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
0

In case for some reason you can't use the build helper plugin the easiest way (albeit not as convenient and somewhat tedious) I have found to deal with this is:

  1. Separate the generated source code into its own project or sub module.
  2. You will want to keep this project predominately closed or not imported into Eclipse when you are working on the parent project.
  3. In the parent project that needs the generated code make sure to now depend on the generated source code project via Maven pom dependency.
  4. When you need to update the generated code go to the generated code project and run mvn install. Now refresh the parent project by right clicking and selecting Maven->Update Project...

This generally works well for projects that use a semi static source for code generation such as SOAP WSDLs (Apache CXF) or code generated from a database (jOOQ). For APT and other AspectJ-like-code it doesn't work as well because you are editing the source frequently.

Adam Gent
  • 47,843
  • 23
  • 153
  • 203
0

For new visitors to this question -

build helper maven plugins and m2e connectors go hand in hand. Older versions (before 2.0) of build helpers have moved into an eclipse archive link

build helper versions archived

Pick the correct link from the list and add it as an eclipse update site. It should ask you for a bunch (seriously.. a huge bunch ) of eclipse updates . Please accept and you are good to go.

Gautam
  • 1,030
  • 13
  • 37
-1

the configuration to the build helper plugin did work for us.

but be aware, that the destination folder always has to be equal to the configuration of the plugin u're using for the annotation processing itself.

for example the maven-processor-plugin uses the target folder ${project.build.directory}/generated-sources/apt as default. if you wish another destination for your generated source files you can set it by the tag as shown below.

<plugin>
<groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>process-sources</phase>
                        <configuration>
                            <defaultOutputDirectory>apt_generated</defaultOutputDirectory>
                            <processors>
                                <processor>com.any.processor.invoker</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Hannes Kogler
  • 469
  • 6
  • 12
-3

Here is the solution

  1. Open Marker View (Window > Show View
  2. Right-click on the Error message
  3. Select Quick Fix
  4. Click Finish
imesh
  • 123
  • 1
  • 2
  • 11