You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by offbynull-maven <of...@offbynull.com> on 2015/03/27 02:10:56 UTC

Proper way to have my Mojo instrument both main and test classes

I've written a Maven plugin. When it runs, I want it to process both 
main classes and test classes. I originally thought that setting my 
mojo's defaultPhase to PROCESS_CLASSES would handle this, but I've come 
to find out that PROCESS_CLASSES is only for main classes. There seems 
to be separate phase for test classes: PROCESS_TEST_CLASSES. So, when I 
do mvn clean install, my test classes don't get instrumented but my main 
classes do.

What is the proper way to have a single goal process both test classes 
and main classes? Is there a way to have two default phases? or should I 
have separate goals, one for main classes and one for test classes? or 
should I tell the user to explicitly specify two execution blocks in 
their pom (one for bound to process-classes and the other to 
process-test-classes -- but then how would I find out which phase I'm in 
so that I can target the appropriate directory)?



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


Re: Proper way to have my Mojo instrument both main and test classes

Posted by Anders Hammar <an...@hammar.net>.
You should have two separate goals (sharing most of hte same
code/functionality though). The end user could specify one single execution
block but specifying both goals in it.

You shouldn't need to know which phase you're in. The onyl thing you're
interested in (in the goal) is the classes to process. So each of the two
goals needs to have a method returning this. Having a look at similar
plugins would give you much of the structure. E.g. the aspectj maven
plugin. Or the jboss aop plugin.

/Anders

On Fri, Mar 27, 2015 at 2:10 AM, offbynull-maven <
offbynull-maven@offbynull.com> wrote:

> I've written a Maven plugin. When it runs, I want it to process both main
> classes and test classes. I originally thought that setting my mojo's
> defaultPhase to PROCESS_CLASSES would handle this, but I've come to find
> out that PROCESS_CLASSES is only for main classes. There seems to be
> separate phase for test classes: PROCESS_TEST_CLASSES. So, when I do mvn
> clean install, my test classes don't get instrumented but my main classes
> do.
>
> What is the proper way to have a single goal process both test classes and
> main classes? Is there a way to have two default phases? or should I have
> separate goals, one for main classes and one for test classes? or should I
> tell the user to explicitly specify two execution blocks in their pom (one
> for bound to process-classes and the other to process-test-classes -- but
> then how would I find out which phase I'm in so that I can target the
> appropriate directory)?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>