

By default, a separate coverage report will be generated for each module. Add coverage in a multi-module Maven projectįor multi-module Maven projects, you configure the jacoco-maven-plugin in a profile in the parent pom just as in the single module case, above. The path can be either absolute or relative to the project root. See coverage analysis parameters for details. Wildcards and a comma-delimited list of paths are supported. app-it/target/site/jacoco-aggregate/jacoco.xml If you need to change the directory where the report is generated, you can set the property either on the command line using Maven’s -D switch: mvn = Just launch: mvn sonar:sonar -PcoverageĪs usual and the report will be picked up. This location will be checked automatically by the scanner, so no further configuration is required. The section of your pom.xml should look something like this: īy default, the generated report will be saved under target/site/jacoco/jacoco.xml. Here, we explicitly specify XML, since that is the only one we need for SonarQube. By default, the tool generates XML, HTML, and CSV versions of the report. In the most basic case, we will need to execute two goals: jacoco:prepare-agent, which allows coverage info to be collected during unit tests execution, and jacoco:report, which uses data collected during unit test execution to generate a report.

Typically, you would create a specific Maven profile for executing the unit tests with instrumentation and producing the coverage report only on demand. To add coverage to your Maven project you need to use the jacoco-maven-plugin and its report goal to create a code coverage report.

You then need to configure your analysis to tell the SonarScanner where the report is located so that it can pick it up and send it to SonarQube, where it will be displayed on your project dashboard along with the other analysis metrics.įor Java projects, SonarQube directly supports the JaCoCo coverage tool (see Generic Test Data for information on integrating other coverage tools). Instead, you must set up a third-party tool to produce the report as part of your build process. However, SonarQube does not generate the coverage report itself. SonarQube supports the reporting of test coverage as part of the analysis of your Java project.
