Messages with level Diagnostic.Kind.NOTE (and others) on Annotation Processors
-
22-07-2021 - |
Pregunta
I have two Maven projects:
- The first defines an annotation, an annotation processor and a provider-configuration file to trigger the annotation processor through the ServiceLoader API.
- The other depends on the first and defines some classes and interfaces, and one of them is annotated with the annotation defined in the first project.
I invoke the build of the second project (after having built and installed the first) with mvn clean && mvn compile
, just to be sure that compilation will happen and that annotation processing will run. It works as expected: the simple annontation processor just generates a resource file in the target/classes/
directory containing some dummy data.
When I tried to output some information using processingEnv.getMessager().printMessage(...)
I started having some trouble. If I use Diagnostic.Kind.ERROR
, the build stops and it prints the message, as I would expect. However, with any other Kind
(such as NOTE
or WARNING
), the message is not written on the screen!
Some information on my environment:
Kubuntu 12.10
Linux 3.5.0-17-generic
Apache Maven 3.0.4 (r1232337; 2012-01-17 06:44:56-0200)
Java version: 1.7.0_09, vendor: Oracle Corporation
I didn't explicitly declare the version of maven-compiler-plugin
anywhere, so it must be using the default version (2.3.2? I'm not sure).
How does one enable the output of all the Kind
s of messages on this setup? (ie, launching the annontation processor through maven)
Solución
Apparently, this is a bug in maven-compiler-plugin that has not been fixed: MCOMPILER-66 - Compiler swallows messages from annotation processors.
Otros consejos
Try to add following lines:
<configuration>
<showWarnings>true</showWarnings>
</configuration>
into the maven compiler-plugin definition in the pom.xml of the project. This solution works for me.