Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven site plugin does not include Jacoco reports

I've integrated the jacoco-maven-plugin in my project, based on this excellent guide: http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/

The Jacoco plugin runs fine. However, the maven-site-plugin does not include the Jacoco reports in the site. To be more specific: the 'Project Reports' section does not list the Jacoco reports. The Jacoco reports themselves are available in the target/site/jacoco-ut and target/site/jacoco-it directories.

Here's what I did (without success so far).

First, included the jacoco-maven-plugin as a plugin in the build section of my pom.xml, as explained in the guide referenced above. I'm using Jacoco version 0.6.4.201312101107.

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.plugin.version}</version>
  <executions>
    <!-- scissors... -->
    <!-- report goal is bound to the pre-site phase -->
  </executions>
</plugin>

Second, included the jacoco-maven-plugin in the report section of my pom.xml: no success.

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.plugin.version}</version>
</plugin>

Third, tried to add a reportsets section to the jacoco-maven-plugin in the report section: no success.

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.plugin.version}</version>
  <reportSets>
    <reportSet>
      <reports>
        <report>report</report>
      </reports>
    </reportSet>
  </reportSets>
</plugin>

Can anyone help me to make the maven-site-plugin reference the coverage reports generated by Jacoco in the 'Project Reports' section of the site?

like image 417
Kristel Avatar asked Jan 10 '14 15:01

Kristel


People also ask

Where is JaCoCo report?

By default, a HTML report is generated at $buildDir/reports/jacoco/test .

Why is JaCoCo not showing coverage for some classes?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.

How do I skip JaCoCo in maven?

The check goal has a skip parameter: eclemma.org/jacoco/trunk/doc/check-mojo.html#skip - so it would be -Djacoco. skip=true - it seems this skips all of the jacoco goals.


1 Answers

I've found jacoco to be very tricky, the below config worked for me, i put it together from bits and pieces from blogs in the properties

<jacoco.reportPath>${main.basedir}/target/jacoco.exec</jacoco.reportPath>
    <jacoco.itReportPath>${main.basedir}/target/jacoco-it.exec</jacoco.itReportPath>

inside the build

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.6.4.201312101107</version>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <propertyName>utCoverageAgent</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        </configuration>
                    </execution>
                    <!-- prepare agent for measuring integration tests -->
                    <execution>
                        <id>agent</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.itReportPath}</destFile>
                            <propertyName>itCoverageAgent</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

       <!-- Reporting plugins -->
        <plugin>
            <artifactId>maven-site-plugin</artifactId>
            <version>${plugin.site.version}</version>
            <configuration>
                <attach>true</attach>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-changelog-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <type>range</type>
                            <range>1</range>
                            <!--<displayFileDetailUrl>${project.scm.url}/tree/master/%FILE%</displayFileDetailUrl>-->
                            <headingDateFormat>MM-dd-yyyy</headingDateFormat>
                            <outputEncoding>${project.reporting.outputEncoding}</outputEncoding>

                        </configuration>
                        <reports>
                            <report>changelog</report>
                        </reports>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.7</version>
                        <configuration>
                            <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                            <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                        </configuration>
                        <!-- simpler configuration without reportSets available for usual cases -->
                        <!-- distribution-management, index, dependencies, help, issue-tracking, plugins, cim,
                        license, dependency-management, mailing-list, project-team, dependency-convergence,
                        scm, plugin-management, modules, summary -->
                        <reports>
                            <report>index</report>
                            <report>dependencies</report>
                            <report>issue-tracking</report>
                            <report>scm</report>
                            <report>summary</report>
                        </reports>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jxr-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <aggregate>true</aggregate>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                            <reports>
                                <report>javadoc</report>
                                <report>aggregate</report>
                            </reports>
                        <configuration>
                            <failOnError>false</failOnError>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.6.4.201312101107</version>
                    </plugin>

                </reportPlugins>
            </configuration>
            <executions>
                <execution>
                    <id>attach-descriptor</id>
                    <goals>
                        <goal>attach-descriptor</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Hope that helps !

like image 182
GMelo Avatar answered Nov 30 '22 21:11

GMelo