When uploading to Soanr, the project has a number of unit tests, but the coverage is 0
Modify pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<!--<exclude>**/Abstract*.java</exclude>-->
<!--<exclude>**/*Service.java</exclude>-->
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
If necessary, to bring parameters
clean cobertura:cobertura -Dcobertura.report.format=xml package -Dmaven.test.failure.ignore=true sonar:sonar -Dsonar.language=java
When scanning a multi-module project uploaded to the Sonar by Jenkins, code coverage is very low, covering only a single code module, then the problem can be solved by configuring JaCoCo.
Reference material
Modify pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
By clean org.jacoco:jacoco-maven-plugin:prepare-agent jacoco:report-aggregate install
may be generated at a target jacoco-aggregate
reports cover
Note: jacoco versions earlier than 0.7.9
jacoco:report-aggregate
parameter may not exist
multi-module project to integrate coverage you can also specify thereport
directory
<properties>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>