2

I am building a Java 11 application with Maven.

I have a modularized annotation processor as a dependency and I want it to be discovered and run by javac, but I cannot make it work as expected. (Or maybe my expectations are wrong?)

I have provides Processor with ... in my module-info file, and don't have any files in META-INF/services in processor jar, that is new way ServiceLoader works, right? This processor jar is passed to javac in --module-path property, but no processors were executed.

I tried specifying this dependency in <annotationProcessorPaths> for compiler plugin, but it uses -processorpath propery, which is an old way! This dependency doesn't have META-INF/services, so no processors were detected and run.

When I manually specified this in <compilerArgs>:

--processor-module-path=${settings.localRepository}/<path_to_my_jar>

...then processor was found and executed!

So, javac has a "default annotation processor discovery process" and here is an old answer about it: What is the default annotation processors discovery process?

But this discovery process isn't working for me since Java 9.

Despite my processor jar is in modulepath, no processors gets found until I manually specify processor jar with --processor-module-path.

So there are 2 problems:

  1. Javac doesn't find an annotation processor in modulepath
  2. Maven compiler plugin doesn't have any way to specify modularized annotation processors except raw <compilerArgs>

Am I missing something?

YaaZ
  • 380
  • 2
  • 11
  • 1
    --processor-module-path is the right option to use, you shouldn't expect javac to locate annotation processors on the module path specified to javac with --module-path. – Alan Bateman Oct 31 '18 at 13:16
  • 1
    @AlanBateman May I ask why the inconsistency? If `--processor-path` is not specified then javac will locate annotation processors on the `--class-path`, why is it different for `--processor-module-path` and `--module-path`? – Slaw Oct 31 '18 at 17:10

0 Answers0