maven中的注释处理器输出 [英] Annotation processor output in maven

查看:245
本文介绍了maven中的注释处理器输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSR 269作为在编译期间分析代码的方法,并在需要时将其失败。
我在maven中显示我的注释处理器的输出时遇到了麻烦(Ant确实显示了输出)
我正在使用javax.annotation.processing.Messager来显示警告和错误,但在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?

推荐答案

我认为你遇到了Maven错误或更好的编译器插件中的错误 - MCOMPILER-66 。在注释处理方面,编译器插件有几个问题,例如 MCOMPILER-62 。真正最好的选择imo是禁用编译器插件的注释处理并使用 行家处理器的插件 。在这个博客文章中,您可以看到如何使用它。它看起来像这样:

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.

这篇关于maven中的注释处理器输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆