Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running maven goal in multiple lifecycles

I have a case where I want to run the cobertura plugin in both the verify phase and the reporting phase. I have two profiles and they should both be running the cobertura plugin, but in profile A, I only want to create the xml/html output, but in profile B, I will be generating full site documentation that includes these results.

I have cobertura configured as a plugin that runs as part of the verify phase, but if I do that, even if I run mvn verify site, the cobertura report does not appear in the site documentation. It seems as though I need to have it listed in both the plugins and the reporting section (since I won't be running site in profile A, it won't get called in that profile if I only have it in the plugins). So far the plugins section of my POM includes:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin </artifactId>
<version>2.2</version>
<configuration>
    <instrumentation>
        <excludes>
            <exclude>com/somepkg/**</exclude>
        </excludes>
    </instrumentation>
    <formats>
        <format>xml</format>
        <format>html</format>
    </formats>
</configuration>        
<executions>
    <execution>
        <phase>verify</phase>
        <goals>
            <goal>cobertura</goal>
        </goals>
    </execution>
</executions>
</plugin>

I don't want to copy this into the reporting section too since this is a lot to duplicate. Is there a good way to accomplish this otherwise?

Thanks,

Jeff

like image 486
Jeff Storey Avatar asked Jul 09 '09 11:07

Jeff Storey


People also ask

Are Maven goals tied to phases?

In Maven the "verbs" are goals packaged in Maven plugins which are tied to a phases in a build lifecycle. A Maven lifecycle consists of a sequence of named phases: prepare-resources, compile, package, and install among other. There is phase that captures compilation and a phase that captures packaging.

Does each Maven plugin provide only one goal?

A plugin can have one or more goals. One or more goals need to be specified when configuring a plugin in a POM. Additionally, in case a plugin does not have a default phase defined, the specified goal(s) can be bound to a phase.

How many standard lifecycles does Maven have?

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.


1 Answers

Define this:

<executions>
        <execution>
                <phase>verify</phase>
                <goals>
                        <goal>cobertura</goal>
                </goals>
        </execution>
        <execution>
                <phase>pre-site</phase>
                <goals>
                        <goal>cobertura</goal>
                </goals>
        </execution>
</executions>
like image 154
David Rabinowitz Avatar answered Oct 10 '22 09:10

David Rabinowitz