views:

354

answers:

2

hi,

If i define a plugin in the <build> tag and want to use this in my site command how do i do that? Do i have to define the plugin within <reporting> tag again?

And how about the configuration which i probably have done within the build tag and want to take place at the reporting tag as well? (i dont want to specifie for example a location of a configuration file twice just to use a plugin in 2 lifecycles)

As example: I define my checkstyle plugin in the build tag and configrue a custom location for the rules to be used. I do that because the rules are packed in a jar so i can define it as dependency. This would not be possible if i do it in the reporting tag. But i need to use this plugin in the reporting tag aswell so surfire can generate a report for checkstyle. So i have to define the plugin within the reporting tag aswell.

Maybe i'm doing something complete wrong here but i don't see how i can do it other then that. What i dont like is that i have 1 plugin twice in my pom (in the build tag and reporting tag).

I hope somebody can verify my solution is ok, or give me an advise how to do it better.

thx

kuku

+4  A: 

A maven plugin is typically bound to execution in a given lifecycle phase when you define it. The plugin itself specifies which lifecycle phase this is, but you can change this if you have special needs.

If you have a multi-module build you can define a set of plugins with all parameters required in a common parent-pom. This will normally be executed for every sub-module in the build. If you do not want this to happen you can define it (in the parent pom) like this:

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>true</skip>
       </configuration>
   ... More plugin cofniguration stuff ...
 </plugin>

If you in one or more nested moudules want to enable this plugin you can just say:

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>false</skip>
       </configuration>
   ... Maybe Configuration ....
 </plugin>

In that specific module. You can choose if you want to reconfigure the default parameters which are inherited from the parent definition or not.

I think this is what you're looking for ?

krosenvold
oh i didn't know about that. So basicly i dont need to add checkstyle and pmd plugin into the reporting tag of the pom because they most likly are bounded to site lifecycle right ?
kukudas
If they are declared in the super pom, then yes. You may want to verify that this works as you think ;)
krosenvold
Should i define them under build - plugins - plugin or build - pluginmanagement - plugins - plugin ? I will try it thx.
kukudas
We generally set up the artifactid/groupid/version under plugin -management
krosenvold
+2  A: 

In addition to KRosenvold's answer, you can also minimize configuration by declaring a plugin in the <pluginManagment> section, perhaps at your topmost pom in the inheritance chain, and then you can omit specifying the version of the plugin in all the other places you are declaring it's use.

Parent Pom:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-1</version>
        </plugin>
    </plugins>
<pluginManagement>

Child Pom:

<plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
    </plugin>
</plugins>
Matthew McCullough