iGili
iGili

Reputation: 883

Annotation processor output in maven

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?

Upvotes: 21

Views: 10024

Answers (2)

Réda Housni Alaoui
Réda Housni Alaoui

Reputation: 1452

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

Upvotes: 8

Hardy
Hardy

Reputation: 19129

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.

Upvotes: 16

Related Questions