Generating a maven site including a Cobertura Report
Asked Answered
S

6

7

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?

Stipe answered 27/2, 2009 at 21:25 Comment(0)
S
3

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.

Stipe answered 11/3, 2009 at 17:55 Comment(1)
You should file this as bugs in maven's bug tracker, otherwise it will not be worked on.Irresponsive
J
3

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

Jail answered 1/3, 2009 at 7:50 Comment(0)
S
3

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.

Stipe answered 11/3, 2009 at 17:55 Comment(1)
You should file this as bugs in maven's bug tracker, otherwise it will not be worked on.Irresponsive
G
1
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.

Gardel answered 27/2, 2009 at 23:5 Comment(0)
R
1

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.

Raye answered 11/10, 2010 at 5:12 Comment(0)
T
0

We use

mvn site-deploy

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

Turnbull answered 27/2, 2009 at 22:52 Comment(1)
But I don't want to deploy it to its "production" location, I want a local preview first as this is still experimental.Stipe
S
0

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

Scheming answered 1/3, 2009 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.