Annotation processing in Eclipse

403 views
Skip to first unread message

Larkin Lowrey

unread,
Feb 21, 2019, 9:33:44 PM2/21/19
to GWT Users
It's a slightly off-topic question but possibly an issue familiar to GWT developers.

I'm using Dagger2 and AutoFactory and am quite happy with both. Eclipse, however, does not play nicely with them. After saving any change, I will usually end up with a broken build because Dagger doesn't generate the _Factory classes for the AutoFactory Factory classes. It's acting like the Dagger annotation processor goes first, then AutoFactory's. IOW, when the Dagger processor runs the AutoFactory Factory sources are absent and so Dagger can't generate its code that uses them. IIRC, if any annotation processor generates source files the cycle should be repeated until no new sources are generated. It seems like Eclipse isn't doing that.

I can resolve this by running 'Maven -> Update Project...' so Eclipse's m2e is able to get it right so it seems the incremental build functionality is where the issue lies.

I've tried all three m2e annotation processing settings (auto, experimental, off) with no observable difference in behavior.

My pom does not explicitly declare annotation processor configuration and relies only on auto-discovery.

Are there any Eclipse users out there who are using multiple annotation processors?

Is there a solution to this problem?

Jens

unread,
Feb 22, 2019, 2:42:25 AM2/22/19
to GWT Users
Have you checked the Eclipse error log window? I know we once examined Dagger2 + AutoFactory and there was some bug in Eclipse JDT that caused internal Eclipse exceptions to escape and thrown during annotation processor execution which in turn stopped generating source files. Maybe that issue is still present or reappeared. 

-- J.

Lars

unread,
Feb 22, 2019, 2:40:27 PM2/22/19
to GWT Users
Dagger does not play well with the incremental compiler of eclipse - see https://stackoverflow.com/questions/41178320/does-dagger2-annotation-processor-supports-the-eclipse-incremental-compiler
Background is, that the standard annotation processor does only know things from the current runs and this is limited (by design) for an incremental compiler. Whitout some additional (non-standard) components to see the full code or to give the compiler more hints for the dependencies for the generated classes, this works only with a full compile.

Thomas Broyer

unread,
Feb 23, 2019, 7:03:49 AM2/23/19
to GWT Users


On Friday, February 22, 2019 at 8:40:27 PM UTC+1, Lars wrote:
Dagger does not play well with the incremental compiler of eclipse - see https://stackoverflow.com/questions/41178320/does-dagger2-annotation-processor-supports-the-eclipse-incremental-compiler
Background is, that the standard annotation processor does only know things from the current runs and this is limited (by design) for an incremental compiler. Whitout some additional (non-standard) components to see the full code or to give the compiler more hints for the dependencies for the generated classes, this works only with a full compile.

Dagger works great with Gradle incremental compilation and annotation processing, so it's not a problem of incremental compilation/processing per se, but likely the bugs that litter the Eclipse compiler (see Jens' answer).

Eclipse annotation processing is known to be broken in many ways, though things are getting better with each release, so first make sure you use the very latest version of Eclipse.
You may want to disable "in the editor" processing and explicitly run annotation processing by rebuilding the project (or something like that; I haven't used Eclipse for years, and I don't let my IDE do anything build-related so 🤷)

Larkin Lowrey

unread,
Feb 24, 2019, 5:38:02 PM2/24/19
to GWT Users
On Saturday, February 23, 2019 at 7:03:49 AM UTC-5, Thomas Broyer wrote:
Eclipse annotation processing is known to be broken in many ways...

Yep. I took a look at the logs as Jens suggested and found an exception from the dagger compiler. Eclipse is definitely not doing it right. The dagger processor is being told 'processingOver' twice and, as one might expect, dagger throws an IllegalStateException on the 2nd invocation.

I did find that eclipse allows the order of apt processors to be changed. When I put AutoFactory's first all is good (until eclipse re-orders the list again). This allows me to put together a repeatable test-case for the eclipse folks, should they care to try to address this issue.
 
You may want to disable "in the editor" processing and explicitly run annotation processing by rebuilding the project...

I'm  pretty sure I tried that without success. I'll try it again, though.

Thanks to all for your replies.

Reply all
Reply to author
Forward
0 new messages