7

After reading this: What is the proper way to use Cobertura with Maven 3.0.2 and this: http://www.wakaleo.com/blog/292-site-generation-in-maven-3

my POM file looks like this:

    <build>
    <plugins>
        .....
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.7</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jxr-plugin</artifactId>
                        <version>2.1</version>
                        <configuration>
                            <aggregate>true</aggregate>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-report-plugin</artifactId>
                        <version>2.6</version>
                        <configuration>
                            <skip>true</skip>
                            <useFile>false</useFile>
                            <argLine>-Xmx512m</argLine>
                            <systemProperties>
                                <property>
                                    <name>generateReport</name>
                                    <value>html</value>
                                </property>
                            </systemProperties>
                        </configuration>
                        <executions>
                            <execution>
                                <id>unit-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <includes>
                                        <include>**/UnitTest*.java</include>
                                        <include>**/*UnitTest.java</include>
                                        <include>**/*Scenarios.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                            <execution>
                                <id>integration-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>${integrationTestsSkip}</skip>
                                    <includes>
                                        <include>**/*IntegrationTest.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <instrumentation>
                                <includes>
                                    <include>**/UnitTest*.class</include>
                                    <include>**/*UnitTest.class</include>
                                    <include>**/*Scenarios.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>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.6</version>
                    </plugin>
                </reportPlugins>
            </configuration>
        </plugin>

        ......



    </plugins>
</build>

After running cobertura:cobertura i still don't get any reports. In target cobertura folder is empty and there is no folder called site. Can anyone tell me what did I do wrong? When i was using older approach with maven 2.2 everything worked fine yet with M3 i got bad results.

Community
  • 1
  • 1
Arek
  • 1,941
  • 4
  • 22
  • 27
  • 1
    Can you see the cobertura.ser file anywhere in your build folder? This is what the report is built from so check your directory paths. If that file does not exist are your instrumented-classes being created in your build folder? – Brad Nov 04 '11 at 13:34

3 Answers3

1

Ok, what I have found it is that one might have to explicitly include **/*Test.java in the maven-surefire-plugin's configuration section when configuring special executions in the parent pom or when using a parent at all..... otherweise it did not execute any surefire tests at all during the cobertura execution and the reports always showed zero coverage.

user1050755
  • 11,218
  • 4
  • 45
  • 56
1

Ok, problem solved. Strangely after a few refreshes and rebuilds everything started to work just fine. Ser file was present in directory and now all reports are generated correctly. I am pretty astonished by that :)

Arek
  • 1,941
  • 4
  • 22
  • 27
0

I haven't tried running maven-cobertura-plugin as part of maven-site-plugin.

I did get it to work directly by moving maven-cobertura-plugin out of 'build' and into 'reporting', as in my answer here : Why cobertura reports code coverage as zero for all but one module in multi-module maven project?

Community
  • 1
  • 1
Graham Griffiths
  • 2,196
  • 1
  • 12
  • 15