Generated code not taken into account in maven compile process

安稳与你 提交于 2019-12-10 20:14:08

问题


I have a maven project generating a new class from an annotation processor during a compile process. The class is successfully generated in /target/generated-sources/annotations/, but it is not compiled into the .jar. Why?

<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>

EDIT

This seems to be a known 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.


回答1:


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




回答2:


It seems all you do is compile the classes and not build the jar. You need to use the Maven Jar Plugin This is a usage example.



来源:https://stackoverflow.com/questions/6975298/generated-code-not-taken-into-account-in-maven-compile-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!