Setting the generated source directory for annotation processors in Maven

Robert Munteanu picture Robert Munteanu · Oct 19, 2009 · Viewed 28.6k times · Source

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

Answer

Robert Munteanu picture Robert Munteanu · Oct 19, 2009

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

Submitted patches: