我有一个多模块Maven项目,当我进入Sonarqube时看到0%的覆盖率,但是当我在{module}/target/site/index.html
中查看Jacoco报告时看到了适当的覆盖率
这是我pom.xml的相关部分
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
这是我的sonar-project.properties
文件
## Sonar Scanner Settings File
# SonarQube info
sonar.host.url=xxx
# Project config
sonar.language=java
sonar.projectKey=project
sonar.projectName=project
sonar.projectVersion=1.0-SNAPSHOT
sonar.github.repository=lendup/project
sonar.sources=module1/src/main/java,module2/src/main/java
sonar.tests=module1/src/test/java,module2/src/test/java
sonar.sourceEncoding=UTF-8
# Test Reports
sonar.junit.reportPaths=module1/target/surefire-reports,module2/target/surefire-reports
sonar.jacoco.reportPaths=module1/target/jacoco.exec,module2/target/jacoco.exec
## Java
sonar.java.binaries=module1/target/classes,module2/target/classes
sonar.java.source=1.8
我的项目不使用maven surefire插件,而是将其手动安装到本地仓库中,例如
mvn install:install-file -Dfile=assets/surefire-junit4-2.17.jar -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit4 -Dversion=2.17 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true