views:

2551

answers:

6

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?

A: 

We use

mvn site-deploy

This builds the site and deploys it (copies it to the place we have configured).

ScArcher2
But I don't want to deploy it to its "production" location, I want a local preview first as this is still experimental.
Trampas Kirk
+1  A: 
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.

André
+2  A: 

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

Alex Miller
A: 

mvn site:site should produce what you're after, in the target directory, there will be a site directory containing all reports linked with an index.html in that directory.

MetroidFan2002
A: 

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.

Trampas Kirk
You should file this as bugs in maven's bug tracker, otherwise it will not be worked on.
André
A: 

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 substitue the current directory. This is because the url that you use must be absolute.