【问题标题】:Getting “Skipping JaCoCo execution due to missing execution data file” in local在本地获取“由于缺少执行数据文件而跳过 JaCoCo 执行”
【发布时间】:2021-05-29 04:13:08
【问题描述】:

我有下面的 pom.xml 很好。我能够生成 jacoco.exec 并查看 sonarqube 中的覆盖范围。但问题是当我在本地(我的笔记本电脑)运行代码时。 target/site 文件夹未生成,并且 jacoco 报告未生成 jacoco.exe 生成是我的应用程序的起始文件夹,而不是在 target 文件夹中。 我该如何为本地解决这个问题?

当我运行maven install or maven test时出现以下错误

Skipping JaCoCo execution due to missing execution data file 

我有 maven spring boot 应用程序

pom.xml

 <properties>
        <!-- Sonar -->
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.language>java</sonar.language>
    </properties>
    
    -- snipper of jacoco plugin tag
     <configuration>
            <destFile>${sonar.jacoco.reportPath}</destFile>
            
        </configuration>

【问题讨论】:

  • sonar.jacoco.reportPath 的值看起来很奇怪。为什么要尝试从父目录写入/读取?
  • @DavidM.Karr 那么我应该给什么值。当我运行竹计划时它对我有用。我在 sonarqube 中获得了代码覆盖率。我尝试将值更改为&lt;sonar.jacoco.reportPath&gt;target/jacoco.exec&lt;/sonar.jacoco.reportPath&gt;。这个值有效在本地很好,但我开始在 sonarqube 中获得 0 覆盖率。

标签: maven junit sonarqube code-coverage jacoco


【解决方案1】:

很久以前,我们用“jacoco.xml”文件替换了“jacoco.exec”文件的使用。前者现在应该被弃用了。

我们设置了以下属性:

  • sonar.coverage.jacoco.xmlReportPaths: ${basedir}/target/jacoco_report/jacoco.xml
  • jacoco.path: ${basedir}/target/jacoco_report

在 jacoco 插件配置中,有以下内容:

                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <!-- Ensures that the code coverage report for unit tests is created 
                    after unit tests have been run. -->
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${jacoco.path}</outputDirectory>
                    </configuration>
                </execution>

在surefire插件配置中,我们有这个:

<argLine>${surefireArgLine}</argLine>

【讨论】:

  • 您的项目中${sonar.jacoco.reportPath} 的值是多少?
  • 我不知道。我们不设置或使用它。
  • M.karr 我试过你的配置。它在本地运行良好,但是当我在 sonarqube 服务器上尝试它时显​​示 0% 覆盖率
  • 好的。验证当您进行本地构建时,您可以在浏览器中打开“/target/jacoco_report/index.html”。这将显示覆盖结果。这是接下来要检查的事情。
  • 是的,这就是我说它在本地工作的意思。我可以在本地看到覆盖范围,但在 sonarqube ut 中显示 0
猜你喜欢
  • 2013-08-09
  • 2022-06-14
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多