I have two Maven projects:
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)
The process of generating code at compile time to handle the annotations is called Annotation Processing. The annotation processor can validate, generate, and modify your code based on the annotations, which help you significantly reduce the amount of code you need to write.
Annotations provide information to a program at compile time or at runtime based on which the program can take further action. An annotation processor processes these annotations at compile time or runtime to provide functionality such as code generation, error checking, etc. The java.
Annotation processing is a tool built into javac for scanning and processing annotations at compile time. It can create new source files; however, it can't modify existing ones. It's done in rounds. The first round starts when the compilation reaches the pre-compile phase.
A Java annotation processor is a compiler plug-in that can gather information about source code as it is being compiled, generate additional Java types or other resource files, and post warnings and errors.
Apparently, this is a bug in maven-compiler-plugin that has not been fixed: MCOMPILER-66 - Compiler swallows messages from annotation processors.
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.
See: https://gist.github.com/esamson/0777b97adde4c2f9bc31
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With