Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a maven site including a Cobertura Report

I've got some projects that are already doing site generation via maven, and I want to integrate cobertura reports in them, but no maven goal I seem to run will generate a local preview for me to look at that includes the Cobertura reports in the site. I want to be sure they're generating correctly before I commit the pom changes to the repo and have broken site generated.

Below is what I've added to the maven poms (parent and module), but the site I see when I run mvn site:run does not include the cobertura reports:

<project>
...
    <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <check>
                    <haltOnFailure>false</haltOnFailure>
                    <regexes>
                        <regex>
                            <pattern>parent-package-name-here.*</pattern>
                            <branchRate>80</branchRate>
                            <lineRate>80</lineRate>
                        </regex>
                    </regexes>
                </check>
                <instrumentation>
                    <includes>
                        <include>parent-package-name-here/**/*.class</include>
                    </includes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <id>clean</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>instrument</id>
                    <phase>site</phase>
                    <goals>
                        <goal>instrument</goal>
                        <goal>cobertura</goal>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...
<reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>
</reporting>
...
</project>

What maven command should I use to generate the site with cobertura reports? Or, what should I add (additionally) to get the site generation to include the cobertura reports?

like image 283
Trampas Kirk Avatar asked Feb 27 '09 21:02

Trampas Kirk


People also ask

How do you generate a site for a project with Maven?

To generate a site, just run mvn site:site or mvn site. To view the generated site on a local machine, run mvn site:run. This command will deploy the site to a Jetty web server at the address localhost:8080.

What is cobertura report?

Simply put, Cobertura is a reporting tool that calculates test coverage for a codebase – the percentage of branches/lines accessed by unit tests in a Java project.


2 Answers

Should do:

mvn site

To elaborate, running mvn a:b runs the goal b in plugin a. Saying mvn c means to run the lifecycle phase c, which runs all of the bound goals in all of the phases up to c. As a result, this will trigger a lot more things to happen (such as doing the necessary preparation to produce cobertura reports).

like image 147
Alex Miller Avatar answered Nov 14 '22 20:11

Alex Miller


I figured out how to do this.

It seems there are a lot of bugs in the link generation within the maven site generation plugin.

The only way I've found to make maven generate a local copy of the site with working module links is to modify the distributionManagement/site tag to point to some local directory instead of the real-live deploy directory, then use maven site:deploy.

Every attempt to use mvn site:stage generates broken links. Same goes for mvn site:run.

The report links work with mvn site:run / mvn site:stage but the links to modules do not.

like image 35
Trampas Kirk Avatar answered Nov 14 '22 20:11

Trampas Kirk