Generating a maven site including a Cobertura Report

12,352

Solution 1

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.

Solution 2

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).

Solution 3

mvn site

should do what you are looking for. You configure the plugin to run in the pre-site and site phases of the life cycle but your are then executing the site:run goal not site. We are doing similar things with clover (commercial coverage tool) and mvn site does the trick.

Solution 4

site:stage module links don't work in my experience either for multi module builds but site:deploy does. Try this:

Use a property for the site URL in the parent pom, e.g. ${site.url}. Then call this

mvn clean site site:deploy -Dsite.url=file://`pwd`/target/site-deployed

The pwd is a -nix command that will substitute the current directory. This is because the URL that you use must be absolute.

Share:
12,352
Trampas Kirk
Author by

Trampas Kirk

Updated on June 09, 2022

Comments

  • Trampas Kirk
    Trampas Kirk about 2 years

    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?

  • Craig Curtis
    Craig Curtis over 15 years
    You should file this as bugs in maven's bug tracker, otherwise it will not be worked on.