M2E and having maven generated source folders as e

2019-01-04 06:10发布

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.

11条回答
欢心
2楼-- · 2019-01-04 06:42

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.

查看更多
仙女界的扛把子
3楼-- · 2019-01-04 06:42

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.

查看更多
贼婆χ
4楼-- · 2019-01-04 06:42

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

查看更多
放荡不羁爱自由
5楼-- · 2019-01-04 06:43

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.

查看更多
【Aperson】
6楼-- · 2019-01-04 06:46

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
查看更多
登录 后发表回答