我使用 JSR 269 作为一种在编译期间分析代码并在需要时使它失败的方法。 我在 maven 中显示注释处理器的输出时遇到了问题(Ant 确实显示了输出) 我正在使用 javax.annotation.processing.Messager 来显示警告和错误,但在 Maven 中我看不到它的输出。 (不过我确实知道它会运行,因为它会生成应有的代码)。 有什么想法吗?
最佳答案
我认为您遇到了 Maven 错误或更好的编译器插件中的错误 - MCOMPILER-66 .在注释处理方面,编译器插件有几个问题,例如 MCOMPILER-62 .在我看来,最好的选择是禁用编译器插件的注释处理并使用 maven-processor-plugin .在这个blog post你可以看到如何使用它。它看起来像这样:
<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>
另请注意注解处理器依赖性如何很好地仅限于插件。
关于java - maven 中的注释处理器输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12822087/