Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

M2E and having maven generated source folders as eclipse source folders

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.

like image 543
Michael Wiles Avatar asked Aug 23 '11 11:08

Michael Wiles


People also ask

What is Eclipse m2e settings?

This plugin synchronises the settings done in your project's Maven POM file with the Eclipse settings. All you need to provide is a JAR file with the settings files, and configure the maven-eclipse-plugin in your POM to use these settings.

What is Eclipse m2e?

m2e is a popular Eclipse IDE plugin with stated project goal "to provide a first-class Apache Maven support in the Eclipse IDE".

What is m2e maven?

M2Eclipse provides tight integration for Apache Maven into the Eclipse IDE with the following features: Launching Maven builds from within Eclipse. Dependency management for Eclipse build path based on Maven's pom. xml. Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository.


2 Answers

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 https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html)
like image 193
Michael-O Avatar answered Oct 03 '22 03:10

Michael-O


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.

like image 30
peter Avatar answered Oct 03 '22 04:10

peter