0

我正在为 Scala 项目运行 Teamcity 的目标,因为 org.jacoco:jacoco-maven-plugin:prepare-agent -U sonar:sonar 我的 pom.xml 文件如下所示:

<sonar-maven-plugin.version>2.0</sonar-maven-plugin.version>
<!-- Sonar -->
        <jacoco.version>0.7.9</jacoco.version>
        <sonar.projectName>ds-rfds</sonar.projectName>
        <sonar.projectDescription>ds-rfds</sonar.projectDescription>
        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
        <sonar.scala.coverage.reportPaths>${project.basedir}/ds-rfds/target</sonar.scala.coverage.reportPaths>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.language>scala</sonar.language>
        <junit.version>4.11</junit.version>

我无法得到报告,它给出的错误如下:

Sensor Scoverage sensor for Scala coverage [sonarscala]
18:34:58
    [INFO] Importing coverage from /mrit_cm3/apps/teamcity/7.1.3/buildagent1/work/84f58bcce55c6907/ds-rfds/target
18:34:58
    [ERROR] File '/mrit_cm3/apps/teamcity/7.1.3/buildagent1/work/84f58bcce55c6907/ds-rfds/target' can't be read. java.io.FileNotFoundException: /mrit_cm3/apps/teamcity/7.1.3/buildagent1/work/84f58bcce55c6907/ds-rfds/target (No such file or directory)
18:34:58
    java.io.FileNotFoundException: /mrit_cm3/apps/teamcity/7.1.3/buildagent1/work/84f58bcce55c6907/ds-rfds/target (No such file or directory)

我应该如何解决这个问题?我正在使用 SonarQube 企业版版本 7.9.1

4

1 回答 1

0

SonarQube 不会创建代码覆盖率报告,它只是读取它。我怀疑您缺少将成为板条箱报告的命令。它应该如下所示:

    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.7</version>
    <executions>
     <execution>
         <id>prepare-agent</id>
         <goals>
             <goal>prepare-agent</goal>
         </goals>
     </execution>
     <execution>
         <id>report</id>
         <phase>prepare-package</phase>
         <goals>
             <goal>report</goal>
         </goals>
     </execution>
     <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>target/jacoco.exec</dataFile>
             <!-- Sets the output directory for the code coverage report. -->
             <outputDirectory>target/jacoco-ut</outputDirectory>
         </configuration>
     </execution>
 </executions>
 <configuration>
     <systemPropertyVariables>
         <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
     </systemPropertyVariables>
 </configuration>

注意这<execution><id>post-unit-test</id>部分很重要,因为这里是创建文件的地方。

此外,您需要在 sonarqube 属性(路径:)中设置此路径<SONAR_QUBE_INSTALL_FOLDER>\conf\sonar.properties并添加以下内容:

sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/coverage-reports/jacoco-unit.exec
sonar.binaries=target/classes
sonar.java.coveragePlugin=jacoco
sonar.verbose=true
于 2021-10-13T10:11:26.103 回答