Search code examples
mavenmaven-2buildcoberturamaven-surefire-plugin

Managing report plugins in maven site


I'm using Maven 3 in a multi module project and configured site with following report plugins: 1. findbugs 2. cobertura 3. surefire report for tests

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-site-plugin</artifactId>
              <version>${maven.site.version}</version>
              <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>findbugs-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>cobertura-maven-plugin</artifactId>
                    </plugin>
                     <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-report-plugin</artifactId>
                    </plugin>
                </reportPlugins>
              </configuration>
        </plugin>

If I use:

mvn site -DskipTests=true after mvn clean install

I dot not get proper reports after mvn site. Cobertura related test coverage report does not shows correct data i.e. all packages as 0% test coverage. It seems cobertura wants to run tests itself to determine coverage.

But when I run

mvn site

This makes my all tests run twice once each for cobertura and surefire reports.

I want to run tests only once and generate the required reports. Please let me know the correct way to achieve this using above reportPlugins in maven.


Solution

  • Cobertura and surefire report (for site generation) do two different things. Hence you cannot avoid running the tests twice - once for cobertura and one for site.

    What you could look at is moving the cobertura run out of maven default life-cycle and run it separately as required. This way, mvn site will only run surefire for site generation.