Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

plugin complains about legal unknown annotations #47

Open
chrylis opened this issue Nov 1, 2015 · 6 comments
Open

plugin complains about legal unknown annotations #47

chrylis opened this issue Nov 1, 2015 · 6 comments

Comments

@chrylis
Copy link

chrylis commented Nov 1, 2015

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
Copy link
Member

timowest commented Nov 1, 2015

Does javac only warn or does the code generation fail?

chrylis added a commit to chrylis/querydsl-apt-maven-plugin-47 that referenced this issue Nov 2, 2015
@chrylis
Copy link
Author

chrylis commented Nov 2, 2015

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
Copy link
Member

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
Copy link
Author

chrylis commented Nov 2, 2015

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
Copy link
Member

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
Copy link
Author

chrylis commented Nov 2, 2015

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants