views:

1301

answers:

3

I'm trying to move a build which generates sources using an annotation processor to Maven. I've tried configuring the maven-compiler-plugin as follows:

 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <fork>true</fork>
    <compilerArgument>-s ${project.build.directory}/target/generated-sources/annotation-processing</compilerArgument>
   </configuration>
  </plugin>
 </plugins>

But javac fails with

[INFO] Compilation failure  
Failure executing javac,  but could not parse the error:
javac: invalid flag: -s /home/robert/workspaces/betbrain/sportsengine.common/sportsengine.bean.test/target/target/generated-sources/annotation-processing  
Usage: javac <options> <source files>  
use -help for a list of possible options

As far as I can tell, -s should be passed before the source files to javac, but maven passes it after.

How can I pass the -s flag properly to the maven-compiler-plugin?


Update: the maven-annotation-plugin does not seem to work.

When configured as

  <plugin>
   <groupId>org.bsc.maven</groupId>
   <artifactId>maven-processor-plugin</artifactId>
   <version>1.0-SNAPSHOT</version>
   <executions>
    <execution>
     <id>process</id>
     <goals>
      <goal>process</goal>
     </goals>
     <phase>generate-sources</phase>
     <configuration>
      <outputDirectory>${generated.sources.directory}</outputDirectory>
      <processors>
       <processor>xxx.annotation.EnforceJavaBeansConventionsProcessor</processor>
      </processors>
     </configuration>
    </execution>
   </executions>
  </plugin>

Execution fails with

[INFO] [processor:process {execution: process}]
error: Annotation processor 'xxx.annotation.EnforceJavaBeansConventionsProcessor' not found
1 error
+2  A: 

I may be missing something but shouldn't you:

  1. Generate sources in target/generated-sources/annotation-processing during the generate-sources phase? The apt-maven-plugin or the maven-annotation-plugin could help.

  2. Include generated sources when compiling sources into target/classes using <includes> in the maven-compiler-plugin or the maven-build-helper-plugin?

EDIT: Where is xxx.annotation.EnforceJavaBeansConventionsProcessor located? Don't you need to add dependencies to the configuration of the maven-annotation-plugin as documented on the Usage page?

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <outputDirectory>src/main/generated</outputDirectory><!-- PROCESSOR OUT DIR --> 
        <processors><!-- LIST OF PROCESSOR CLASS(S) -->
          <processor>org.bsc.apt.BeanInfoAnnotationProcessor</processor>
        </processors>
      </configuration> 
    </execution>
  </executions>
  <dependencies/><!-- ADD DEPENDENCIES HERE IF REQUIRED -->
</plugin>

PS: I wouldn't use src/main/generated as output directory but rather a subdirectory of target/generated-sources.

Pascal Thivent
Yes, I should. How should I perform step 1?
Robert Munteanu
Do you use the maven-apt-plugin or the maven-annotation-plugin?
Pascal Thivent
I am now investigating the maven-annotation-plugin - since I'm using the Java 6 APIs, but apparently I'm required to list the processor I'm using, and I can't pass those in properly. Is it possible to bind the maven-compiler-plugin to the generate-sources phase?
Robert Munteanu
Please see my update about the maven-annotation-plugin.
Robert Munteanu
A: 

The plugin was using the harcoded Windows classpath separator to build the classpath, so it was failing on my Linux machine.

Submitted patches:

Robert Munteanu
Good to know. Thanks for the patches :)
Pascal Thivent
A: 

Not exactly an answer to your question, but of interest:

http://jira.codehaus.org/browse/MCOMPILER-75

I'm afraid there are a number of issues using JSR 269 in Maven, at least with the default compiler plugin.

Jesse Glick
With maven-compiler-plugin 2.2, you should not need to do anything to get 269 to discover default processors.
Jesse Glick