Annotation processors and the --processor-module-path
Eirik Bjørsnøs
eirbjo at gmail.com
Tue Nov 22 10:33:15 UTC 2016
Found it!
With --processor-module-path, JavacProcessingEnvironment.java:257 throws an
exception when
calling fileManager.getServiceLoader(ANNOTATION_PROCESSOR_MODULE_PATH,
Processor.class)
There's a catch for this exception at JavaCompiler, line 982:
catch (Abort ex) {
if (devVerbose)
ex.printStackTrace(System.err);
}
Since devVerbose is false, this exception is effectively swallowed.
The exception is an ResolutionException: Module java.xml.bind not found,
required by com.example.annotation.processor
So again, I added -J-add-modules=java.xml.bind, and now my annotation
processor is loading.
Given that my annotation processor does require java.xml.bind and I'm using
--processor-module-path, my expectation would be that javac would resolve
that requires for me.
What gives, am I expecting too much?
Bonus question: What is devVerbose, and how can I enable it?
Eirik.
On Mon, Nov 21, 2016 at 11:39 AM, Eirik Bjørsnøs <eirbjo at gmail.com> wrote:
>
> Currently, AFAIK, the processors on module path need to be registered in
>> the ServiceLoader. For --processor-module-path, "-processor" can be used to
>> select processors out of those registered in the ServiceLoader. If
>> --processor-module-path is used and there is no "-processor", all
>> processors registered in ServiceLoader are considered, AFAIK. Please note
>> that (as before) the processors are only run if their
>> SupportedAnnotationTypes match, etc.
>>
>> I tried a simple example as well, and with the proper "provides" the
>> annotation processor was run. Is there a testcase we could try?
>>
>
>
> Jan,
>
> I've updated the testcase on Github:
>
> https://github.com/eirbjo/java-xml-bind-processor
>
> How to reproduce:
>
> $ mvn clean install
> $ cd example-module
>
> Now (since Maven doesn't know about --processor-module-path):
>
> $ javac -d target/classes --processor-module-path
> ~/.m2/repository/com/example/annotation-processor/1.0-
> SNAPSHOT/annotation-processor-1.0-SNAPSHOT.jar -sourcepath src/main/java
> src/main/java/com/example/module/SomeClass.java
>
> No output - the processor is not applied.
>
> However:
>
> $ javac -d target/classes -classpath ~/.m2/repository/com/example/
> annotation-processor/1.0-SNAPSHOT/annotation-processor-1.0-SNAPSHOT.jar
> -sourcepath src/main/java src/main/java/com/example/module/SomeClass.java
> Running ProcessorUsingJavaXmlBind.process
> java.xml? true
> java.xml.bind? false
>
>
> The processor was now applied.
>
> Note that the test case now has provides in module-info.java _and_ the
> ServiceLoader file in META-INF/services. I tried removing the services
> file, no change.
>
> Eirik.
>
>
>
More information about the jigsaw-dev
mailing list