The javax.annotation.Generated and annotation processors

Alan Bateman Alan.Bateman at oracle.com
Sun Apr 24 07:32:44 UTC 2016


On 23/04/2016 00:14, Sanne Grinovero wrote:
> :
>
> I couldn't try the "-J-addmods -Jjava.annotations.common" solution
> either, I suspect because Maven is getting in the way and possibly
> passing these parameters in the wrong order; for the record this is
> the stack:
>
> Caused by: java.lang.IllegalArgumentException: invalid flag: -J-addmods
>      at com.sun.tools.javac.main.Arguments.error(jdk.compiler at 9-ea/Arguments.java:779)
>      at com.sun.tools.javac.main.Arguments.doProcessArgs(jdk.compiler at 9-ea/Arguments.java:378)
>      at com.sun.tools.javac.main.Arguments.processArgs(jdk.compiler at 9-ea/Arguments.java:294)
>      at com.sun.tools.javac.main.Arguments.init(jdk.compiler at 9-ea/Arguments.java:250)
>      at com.sun.tools.javac.api.JavacTool.getTask(jdk.compiler at 9-ea/JavacTool.java:175)
>      at com.sun.tools.javac.api.JavacTool.getTask(jdk.compiler at 9-ea/JavacTool.java:109)
>      at com.sun.tools.javac.api.JavacTool.getTask(jdk.compiler at 9-ea/JavacTool.java:65)
>      at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled(AbstractAnnotationProcessorMojo.java:527)
The `javac` tool can take -J-addmods ... to pass the options through to 
the runtime (or "execution environment" in javac speak) but here there 
is already an execution environment that is running Maven and invoking 
the compiler via the API.


> But found a solution: your suggestion that this is a similar problem -
> but opposite - then what I had with the Java EE APIs was spot on:
> I simply added the API jar from jsr250 "javax.annotation" on the
> classpath of the annotation processor and it's all working nicely.
Okay, although in some respects then this is a retrograde step. Going 
forward then I would hope that the JSR 250 annotations can be deployed 
as a module on the module path.

>
> I noticed something else which might be of interest. We build the
> project in two distinct phases: annotation processor(s) first,
> compilation second.
> I'm surprised to see that the second phase is working fine even though
> I did not add the jsr250 dependency; I didn't investigate further but
> it seems like the compiler knows that this annotation is annotated
> with "@Retention(SOURCE)" ?!
In the compilation step then are you specifying 
-source/-target/-bootclasspath?

>
> For those using Maven, I pasted an example of this solution here:
>   - https://issues.jboss.org/browse/LOGTOOL-105?focusedCommentId=13196069
>
> BTW all these questions I've been sending recently relate to a popular
> open source project. If anyone would like to experiment with the same
> projects it's available at
> https://github.com/hibernate/hibernate-search .
> It might be of interest as it runs all of: Hibernate ORM, Apache
> Lucene, Elasticsearch, WildFly, JGroups, ApacheMQ which are all very
> popular in the Java community, and runs integration tests within
> Spring/JavaSE, within WildFly (JavaEE), with modules systems: both
> OSGi & JBoss Modules, uses bytecode manipulation including Javassist
> proxies, tests driven by Byteman, and finally building the
> documentation requires JRuby.
>
Thanks for the context, please let us know how you get on as it is 
always useful to know what is working and not working. It would also be 
interesting to try out migrating some of these libraries and components 
to modules some day too.

-Alan


More information about the jigsaw-dev mailing list