3

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.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

2 Answers2

6

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

fgysin
  • 11,329
  • 13
  • 61
  • 94
1

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.

Ali
  • 12,354
  • 9
  • 54
  • 83
  • A jar is built as part of the process, but it does not contain the generated code. – Jérôme Verstrynge Aug 07 '11 at 20:14
  • Oh then check out this thread http://stackoverflow.com/questions/4741220/maven-producing-empty-jar – Ali Aug 07 '11 at 20:32
  • Could you share your project structure / tree? Maven projet structures are supposed to be standard so there shouldn't be a problem. – Ali Aug 07 '11 at 21:52
  • Which plugin did you use to generate the classes? Can you give an example how it looks like? Furthermore the work-a-round for the problem is given in the JIRE Ticket description (build-helper-plugin) – khmarbaise Aug 08 '11 at 08:40
  • @khmarbaise See http://download.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#processing, you don't use a plugin to generate the classes. The processor does it. I have tried the workaround, but it does not work. I put my finding and a test case in the ticket. – Jérôme Verstrynge Aug 08 '11 at 11:22
  • Have you bound the compiler plugin for the annotation processing to a different life-cylce like generate-sources ? It does not look like though...I think you have to have two execution blocks one which generating the things from the annotation processing and the other is really compiling everything and of course not to forget to add the supplemental folder (build-helper-plugin) – khmarbaise Aug 08 '11 at 11:36
  • @khmarbaise Thanks for your suggestion. I have not tried it since the solution/workaround provided by fgysin worked. It think that what you mention should be part of the final fix to the maven-compiler-plugin. – Jérôme Verstrynge Aug 08 '11 at 13:53