Annotation Processor defined in Jar not automatically detected

I've defined an annotation processor and bundled it in a Jar file using the standard structure.  For instance, the fq name of the processor is defined in the javax.annotation.processing.Processor file inside the services directory of the Jar.  After checking "Obtain processors from project classpath" I expected IntelliJ to automatically discover the processor without having to declare its name in the Compiler settings dialog.  In addition I expected it to just work without having to explicitly specify modules.  Should it work that way and I've missed a critical step somewhere or?  Thanks.

Also while I'm here...  It took a bit of thinking regarding debugging an annotion processor.  What I've done basically is pass debug args to javac and suspend it and then connect to it via a separate remote debug config.  I was hoping that by specifying the in-process javac option that it would give me some option to debug locally.  Is there a better way than what I'm currently doing with the remote config?  Thanks again.


1 comment
Comment actions Permalink

Hi Scott,

If you use Annotation Processors page in the settings, then all processors are expected to be explicitly defined. IDEA then runs java compiler with disabled annotation processing and processors are run as a separate compilation stage. So the "obtain processors from classpath" is only an alternative to specifying processor's classpath explicitly. You should explicitly define which processors will be invoked. The same situation with modules - all modules to which processors will be applied, must be specified in the table below.

If you expect your processor to run always, just do not enable "explicit" processor configuration. That way, if the jar with your processor is attached to the modules javac compiles, they will be picked up by javac's autodiscovery mechanism.

You may pass arguments to javac's jvm by prefixing the options in the "Additional options" field with the "-J" prefix, just lilke you do for javac's native console runner.



Please sign in to leave a comment.