Jenkins 插件 - SonarQube - 没有 JaCoCo 执行数据被转储



我在 jenkins 作业中运行 SonarQube(使用 Post-build Actions)。我在使用JaCoCo时遇到了以下问题-

[INFO] [16:57:43.157] Sensor JaCoCoSensor...
[INFO] [16:57:43.157] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/.../target/jacoco.exec
[INFO] [16:57:43.426] Sensor JaCoCoSensor done: 269 ms

结果,我的项目的代码覆盖率为 0%。找不到为什么没有创建jacoco.exec。

我没有将"JaCoCo"配置为由 maven 运行(在我的 pom.xml 中)。我知道过去jacoco.exec无论如何都是创建的(可能是由Sonar本身创建的)。

我做错了什么?我需要在我的pom中配置JaCoCo吗.xml才能工作?谢谢。

来自 Web Java 生态系统:

不再可能让 SonarQube 驱动 单元测试。您现在必须生成 JUnit 和代码覆盖率 (JaCoCo或Cobertura或Clover)在SonarQube之前报告 分析,然后将这些报告提供给SonarQube。

所以你需要在pom中包含Jacoco.xml:

   <plugin>
       <groupId>org.jacoco</groupId>
       <artifactId>jacoco-maven-plugin</artifactId>
       <version>0.7.0.201403182114</version>
   <configuration>
       <destFile>${basedir}/target/jacoco-unit.exec</destFile>
       <dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
   </configuration>
       <executions>
           ...
       </executions>
   </plugin>

并将此数据文件提供给SonarQube:

sonar.jacoco.reportPath=target/jacoco-unit.exec

根据此博客,您可以通过将以下插件部分添加到您的pom.xml来启用jacoco.exec文件的创建(它对我有用):

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.1.201405082137</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>

最新更新