I'm using JSR 269 as a way to analyze code during compilation and to fail it if needed. I'm having troubles with displaying output of my annotation processor in maven (Ant does show the output) I'm using javax.annotation.processing.Messager to display warnings and errors, but in maven I don't see it's output. (I do know it runs though, because it generates code like it should). Any ideas?
Asked
Active
Viewed 8,671 times
19
-
How does the processor output messages? How do you invoke it? – matt b Oct 10 '12 at 14:43
-
Does the output show if you invoke maven with the `-X` parameter? – Jörn Horstmann Oct 10 '12 at 14:59
-
1@matt b I'm using javax.annotation.processing.Messager to display warnings: `_messager=processingEnv.getMessager();` @Jorn: I don't use the -X parameter, the processor is listed as a service provider – iGili Oct 10 '12 at 15:45
-
I was asking more about how the processor outputs it's messages - to a logger, to standard out, etc? – matt b Oct 10 '12 at 16:10
-
The messager API provides a way to output messages to stdout. It supposed to display compilation warnings, just like the compiler does. – iGili Oct 11 '12 at 09:06
-
The only answer below isn't accepted. Is there some other answer that is more correct at this point in time? – Patrick Oct 23 '12 at 16:04
-
I had to attend to other stuff (our POC should be released soon) but I will try and update soon. – iGili Oct 24 '12 at 12:43
2 Answers
15
I think you are running into a Maven bug or better a bug in the compiler plugin - MCOMPILER-66. When it comes to annotation processing the compiler plugin has several problems, eg also MCOMPILER-62. Really the best option imo is to disable annotation processing for the compiler plugin and use the maven-processor-plugin. In this blog post you can see how to use it. It looks like this:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.7</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.1.0.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
Note also how the annotation processor dependency is nicely scoped to the plugin only.
8
You can do this by enabling showWarnings flag in the maven-compiler-plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
See also https://github.com/Cosium/annotation-processor-logger#enable-all-logging-levels

Réda Housni Alaoui
- 1,244
- 2
- 15
- 22
-
2Note that this not only enables `WARNING` and `MANDATORY_WARNING`, but also `NOTE` and `OTHER`, which will be displayed by Maven as `INFO`. – rü- Dec 14 '18 at 13:29
-
1