我正在使用JSR 269作为编译期代码分析的一种方式,并在需要时对其进行失败处理。 但是,我在maven中显示注释处理器输出方面遇到了困难(Ant确实显示输出)。 我使用javax.annotation.processing.Messager来显示警告和错误,但在maven中我没有看到它的输出。(我知道它运行了,因为它生成了代码,就像它应该做的那样)。 有什么建议吗?
我正在使用JSR 269作为编译期代码分析的一种方式,并在需要时对其进行失败处理。 但是,我在maven中显示注释处理器输出方面遇到了困难(Ant确实显示输出)。 我使用javax.annotation.processing.Messager来显示警告和错误,但在maven中我没有看到它的输出。(我知道它运行了,因为它生成了代码,就像它应该做的那样)。 有什么建议吗?
我认为你遇到了Maven的一个bug或者更好地说是编译器插件的一个bug - MCOMPILER-66。当涉及注解处理时,编译器插件存在一些问题,比如还有MCOMPILER-62。在我看来,最好的选择是禁用编译器插件的注解处理,并使用maven-processor-plugin。在这篇博客文章中,你可以看到如何使用它。它看起来像这样:
<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>
请注意注解处理器依赖项被很好地限定在插件中。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
还可以参考https://github.com/Cosium/annotation-processor-logger#enable-all-logging-levels
<fork>true</fork>
,尤其是你可能需要<verbose>true</verbose>
。 - mernst
_messager=processingEnv.getMessager();
@Jorn: 我不使用-X参数,处理器被列为服务提供者。 - iGili