在Maven编译过程中不考虑生成的代码 [英] Generated code not taken into account in maven compile process

查看:442
本文介绍了在Maven编译过程中不考虑生成的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,在编译过程中会从注释处理器生成一个新类.该类已在/target/generated-sources/annotations/中成功生成,但未编译到.jar中.为什么?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>${project.build.source}</source>
        <target>${project.build.target}</target>
        <encoding>${project.build.sourceEncoding}</encoding>
        <compilerArgument>-Xlint</compilerArgument>
        <annotationProcessors>
                <annotationProcessor>net.preprocessing.MyAnnotationProcessor</annotationProcessor>
        </annotationProcessors>
    </configuration>
</plugin>

编辑

这似乎是一个已知的错误.如果有人可以解决此问题,欢迎您.

编辑2

我昨天进行了一些测试,但是故障单中建议的解决方法不起作用.我提供了一个测试用例.如果有人对如何解决此问题有见识,欢迎您.请记住,我是注释处理的新手,因此可能有些明显的东西我不见了.

解决方案

我建议使用 maven-processor-plugin 代替传递给Maven编译器的'annotationProcessor'参数./p>

据我所读,似乎编译器Argumens存在一些问题,使用maven-processor-plugin可以解决这些问题.

在这里您可以找到有关maven-processor-plugin的更多信息: http://maven-annotation-plugin.googlecode.com/svn/docs/usage.html

这是一个处理器插件如何替换CompilerArguments的示例(该示例使用了Hibernate Metamodel Generator,但是对于所有类型的注释处理器,它的外观都差不多...):bug. If anyone has an operational workaround, it is welcome.

EDIT 2

I have performed some tests yesterday, but the suggested workaround in the ticket does not work. I have provided a test case. If anyone has insight on how to solve this issue, it is welcome. Keep in mind that I am a newbie at annotation processing, so there might be something obvious I am missing.

解决方案

I would suggest using the maven-processor-plugin instead of an 'annotationProcessor' argument which you pass to the maven compiler.

From what I've read there seem to be some issues with the compilerArgumens, those are solved when you use the maven-processor-plugin.

Here you can find more info about the maven-processor-plugin: http://maven-annotation-plugin.googlecode.com/svn/docs/usage.html

Here is an example of how the processor plugin replaces compilerArguments (the example uses Hibernate Metamodel Generator, but this will look about the same for all kinds of annotation processors...): http://relation.to/Bloggers/HibernateStaticMetamodelGeneratorAnnotationProcessor

这篇关于在Maven编译过程中不考虑生成的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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