You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by lilyevsky <le...@yahoo.com> on 2010/12/09 05:35:37 UTC

Using annotationProcessor in maven-compiler-plugin

I am trying to learn how to use annotationProcessor feature with
maven-compiler-plugin 2.3.2 under maven 3.
My configuration is below.
The processor indeed works and it generates the files. 
My problem is that the compiler does not see those files during compile
phase. What am I doing wrong?
I tried to put my generated-sources in different places, under target,
directly under the project folder.
I tried to use generated-sources/src/main/java structure. Nothing works.

=============================================

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                   
<generatedSourcesDirectory>generated-sources/src/main/java</generatedSourcesDirectory>
                    <annotationProcessors>
                       
<annotationProcessor>com.newamsterdam.framework.flexrecord.FlexRecordProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>
            </plugin>
        </plugins>
    </build>
-- 
View this message in context: http://maven.40175.n5.nabble.com/Using-annotationProcessor-in-maven-compiler-plugin-tp3298435p3298435.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using annotationProcessor in maven-compiler-plugin

Posted by Jörg Schaible <jo...@scalaris.com>.
Hi,

lilyevsky wrote:

> 
> I am trying to learn how to use annotationProcessor feature with
> maven-compiler-plugin 2.3.2 under maven 3.
> My configuration is below.
> The processor indeed works and it generates the files.
> My problem is that the compiler does not see those files during compile
> phase. What am I doing wrong?
> I tried to put my generated-sources in different places, under target,
> directly under the project folder.
> I tried to use generated-sources/src/main/java structure. Nothing works.
> 
> =============================================
> 
> <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-compiler-plugin</artifactId>
>                 <version>2.3.2</version>
>                 <configuration>
>                     <source>1.6</source>
>                     <target>1.6</target>
>                    
> <generatedSourcesDirectory>generated-
sources/src/main/java</generatedSourcesDirectory>
>                     <annotationProcessors>
>                        
> 
<annotationProcessor>com.newamsterdam.framework.flexrecord.FlexRecordProcessor</annotationProcessor>
>                     </annotationProcessors>
>                 </configuration>
>             </plugin>
>         </plugins>
>     </build>

I've never used the annotationProcessor myself, but you might define an  
execution for the source generation and tie it to the generate-source phase. 
I could imagine that the generation of source in the compile phase is simply 
too late.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using annotationProcessor in maven-compiler-plugin

Posted by Anders Hammar <an...@hammar.net>.
Check the source in svn of maven-compiler-plugin.

/Anders (mobile)
Den 9 dec 2010 19.34 skrev "lilyevsky" <le...@yahoo.com>:
>
> Thanks Anders,
>
> I tried the default value and I got one step ahead, not 100% there yet.
> First I run the clean build, it generates the source I want under
> target/generated-sources-annotations. Still complains about the class not
> found when trying to compile the main tree (I use the generated class
there
> for my test). It is interesting to note that the source generation
actually
> is done before it goes to javac, but apparently it is not visible in the
> classpath at that point.
>
> Then I run the build again (without clean). This time my processor is not
> called at all - I guess, the framework knows it's job is done already. It
> compiles the main tree and at this time everything is OK.
>
> I tried maven 2.2.1, the same story.
>
> So I hope there must be some trick I have to do in configuration to make
it
> run in two steps. What can it be?
> You mentioned the integration test. How can I see it?
> --
> View this message in context:
http://maven.40175.n5.nabble.com/Using-annotationProcessor-in-maven-compiler-plugin-tp3298435p3299293.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: Using annotationProcessor in maven-compiler-plugin

Posted by lilyevsky <le...@yahoo.com>.
Thanks Anders,

I tried the default value and I got one step ahead, not 100% there yet.
First I run the clean build, it generates the source I want under
target/generated-sources-annotations. Still complains about the class not
found when trying to compile the main tree (I use the generated class there
for my test). It is interesting to note that the source generation actually
is done before it goes to javac, but apparently it is not visible in the
classpath at that point.

Then I run the build again (without clean). This time my processor is not
called at all - I guess, the framework knows it's job is done already. It
compiles the main tree and at this time everything is OK.

I tried maven 2.2.1, the same story.

So I hope there must be some trick I have to do in configuration to make it
run in two steps. What can it be?
You mentioned the integration test. How can I see it?
-- 
View this message in context: http://maven.40175.n5.nabble.com/Using-annotationProcessor-in-maven-compiler-plugin-tp3298435p3299293.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using annotationProcessor in maven-compiler-plugin

Posted by Anders Hammar <an...@hammar.net>.
I assume you tried the default value for generatedSourcesDirectory?
Haven't used annotation processors myself, my Maven experience just suggests
going with the defaults as much as possible. But if even the defaults don't
work, something is clearly wrong. Either in the plugin or in your config.
:-)

There is an integration-test regarding this for the maven-compiler-plugin.
Have look at that to see how that differs from your setup. Possible also
test with Maven 2.2.1 to see if Maven 3 is the problem.

/Anders

On Thu, Dec 9, 2010 at 05:35, lilyevsky <le...@yahoo.com> wrote:

>
> I am trying to learn how to use annotationProcessor feature with
> maven-compiler-plugin 2.3.2 under maven 3.
> My configuration is below.
> The processor indeed works and it generates the files.
> My problem is that the compiler does not see those files during compile
> phase. What am I doing wrong?
> I tried to put my generated-sources in different places, under target,
> directly under the project folder.
> I tried to use generated-sources/src/main/java structure. Nothing works.
>
> =============================================
>
> <build>
>        <plugins>
>            <plugin>
>                <groupId>org.apache.maven.plugins</groupId>
>                <artifactId>maven-compiler-plugin</artifactId>
>                <version>2.3.2</version>
>                <configuration>
>                    <source>1.6</source>
>                    <target>1.6</target>
>
>
> <generatedSourcesDirectory>generated-sources/src/main/java</generatedSourcesDirectory>
>                    <annotationProcessors>
>
>
> <annotationProcessor>com.newamsterdam.framework.flexrecord.FlexRecordProcessor</annotationProcessor>
>                    </annotationProcessors>
>                </configuration>
>            </plugin>
>        </plugins>
>    </build>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Using-annotationProcessor-in-maven-compiler-plugin-tp3298435p3298435.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>