Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 914
iGili Avatar asked Oct 10 '12 14:10

iGili


2 Answers

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.

like image 50
Hardy Avatar answered Oct 13 '22 00:10

Hardy


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

like image 24
Réda Housni Alaoui Avatar answered Oct 12 '22 22:10

Réda Housni Alaoui