querydsl / apt-maven-plugin

Maven APT plugin
Apache License 2.0
79 stars 41 forks source link

plugin complains about legal unknown annotations #47

Open chrylis opened 9 years ago

chrylis commented 9 years ago

Lombok uses an odd hack to enable capturing annotations to be applied to generated code, which doesn't play nicely with the plugin:

/tmp/java/demo/src/main/java/com/example/DemoController.java:18: error: cannot find symbol
@RequiredArgsConstructor(onConstructor=@__(@Autowired))
                                        ^
  symbol: class __
1 error

The class appears to actually compile correctly later, but the plugin itself complains spuriously, and it might have trouble if a class with an @__ annotation were also an entity.

timowest commented 9 years ago

Does javac only warn or does the code generation fail?

chrylis commented 9 years ago

It's an actual compile error (perhaps this is using a pre-Java-7 compliant annotation-processing pathway), not just a warning, but it looks like the appropriate generated source and class exist. I'm not familiar enough with Querydsl to tell if there's anything wrong with them.

Reproduction (not quite minimal, but close) at https://github.com/chrylis/querydsl-apt-maven-plugin-47

Shredder121 commented 9 years ago

Well, the problem is, as is found in the small print:

Instead, lombok applies the annotations and removes the references so that the error will never actually occur.

So you must use the lombok annotation processor together with the querydsl annotation processor.

This can be done in two ways:

I hope this answers your question, and hope it helps others that run into the problem.

chrylis commented 9 years ago

Hmm, interesting. For some reason (I don't know how it works), Lombok doesn't require specific configuration as an APT processor, or even as a Maven plugin.

I followed the instructions for making the Querydsl APT processor play nicely with m2e; if just omitting that plugin stanza entirely will work, then that would be great, and the docs on Querydsl+Eclipse are just out of date. However, it looks like the second solution as-is generates the source but doesn't get it compiled in an m2e build.

Shredder121 commented 9 years ago

If you make a META-INF/services/javax.annotation.processing.Processor file with the annotation processor in it javac will discover that, since it searches the classpath for annotation processors. We also export that configuration, but the apt plugin enables more fine-grained configuration.

Hope it clears up some things.

chrylis commented 9 years ago

CLI Maven picks up the SPI processor just fine, but m2e doesn't for some reason. Looks like the manual plugin configuration is still required to make m2e behave, and listing any additional processors being run will just have to be part of the SOP.