Skip to end of metadata
Go to start of metadata

To launch JaCoCo as part of your Maven build, use this command: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false

For more details on JaCoCo, see its documentation.

You can also play with this sample project.

There is a known issue on version 0.7.3 of JaCoCo agent producing binary reports incompatible with JaCoCo analyzer 0.7.2 embedded in Java plugin. This issue is fixed with version 0.7.4 of the agent, so please prefer this version.

Java Plugin is compatible with JaCoCo 0.7.5 starting from Java Plugin 3.4 :  SONARJAVA-1091 - Getting issue details... STATUS .

Using argLine

If your project uses the argLine property to configure the surefire-maven-plugin, be sure that argLine defined as a property, rather than as part of the plugin configuration. Doing so will allow JaCoCo to set its agent properly. Otherwise the JVM may crash while tests are running.

That is, argLine should be defined this way: 

	  <properties>
        <argLine>-Xmx128m</argLine>
      </properties>
...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <runOrder>random</runOrder>
        </configuration>
      </plugin>

BEFORE 4.0.0 Force coverage to 0%

By default, when no coverage report is found, the Java Plugin will not set any value for coverage metric. This behavior can be overridden to force coverage to 0% in case of a lack of report by setting the following property : 

sonar.jacoco.reportMissing.force.zero=true

If this property is set while a Jacoco report is provided, this property will have no effect.

Coverage per test (deprecated)

Using some unit test listeners you can collect the information on which lines where covered by which tests and display them in SonarQube. The scope of this functionality extends beyond pure SonarQube capabilities. You will first have to configure a custom SureFire JUnit listener (the actual listener will be org.sonar.java.jacoco.JUnitListener ) , and add a dependency (in your pom.xml) to org.sonarsource.java:sonar-jacoco-listeners . Deprecation notice: this feature is deprecated at SonarQube level and will no longer receive further improvements/maintenance.

  • No labels