Home > Mobile >  Eclipse: compile errors when processing maven-apt-plugin-generated source files
Eclipse: compile errors when processing maven-apt-plugin-generated source files

Time:01-27

I have a project that uses JPA QueryDSL. For that we use the com.mysema.maven:maven-apt-plugin to generate the so-called Q-classes (i.e. Java-code) in Maven phase generate-sources. The generated files are placed into directory <project_root>/target/generated-sources. Subsequently, in phase process-sources we execute the org.codehaus.mojo:build-helper-maven-plugin to add that directory to the source path. Finally that Java code then gets compiled in phase compile.

This setup works all fine when executing the build on the Maven command line.

When I try to run the build inside Eclipse I always get compile errors in some of the generated classes stating that it can not find one of the other generated classes that it refers to (some of the generated classes refer to other generated classes).

That class which is flagged as missing, however, does exist, but it seems as if the Eclipse compiler starts compiling the generated sources right away before the generation of all those files is complete, in this case before a class A is generated to which the generated class B refers to.

This is using the currently latest Eclipse version (2022-12) and I have defined M2E lifecycle mappings to execute these two plugins on configuration but not on incremental builds:

...
<execute>
    <runOnConfiguration>true</runOnConfiguration>
    <runOnIncremental>false</runOnIncremental>
</execute>
...

(I have also given it a try to run them on incremental builds but that didn't change anything.)

Any idea how to teach the Eclipse compiler to wait with compilation until ALL generated files are fully generated? Or any other idea why the Eclipse compiler apparently doesn't "see" files that have been generated?

Hope I could make myself clear...

CodePudding user response:

With Eclipse >=v2022-09 (according to @howlger, I myself only tested it with v2022-12) the issue is fixed by specifying <m2e.apt.activation>jdt_apt</m2e.apt.activation> in the pom.xml's properties section.

Caveats:

  1. for our multi-module project I had to select Maven --> Disable Workspace resolution for several modules that still showed errors despite that setting.
  2. with these settings the build now succeeds and shows no more errors - albeit only after a few days of "burn-in" (c.f. my misc. comments). Initially those "class-not found" errors re-surfaced for a few days, but then for some reason disappeared. Maybe that disappearance has to do with my removal of the old "lifecycle-mappings" for said plugin from the pom.xml.
  • Related