3

使用:

  • SonarQube 社区版 v. 7.9.1
  • 声纳-maven-plugin v. 3.6.0.1398
  • jacoco-maven-plugin v. 0.8.4

我正在尝试从我的 java maven 项目上传 JaCoCo 覆盖率报告。我按照此链接和此示例中提供的说明进行操作。

我使用了以下配置文件配置:

<profiles>
    <profile>
        <id>coverage</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

为了执行我正在运行的扫描:

mvn clean verify sonar:sonar

我得到了这个日志:

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ componente-procesos ---
[INFO] Building jar: C:\Users\Usuario\Documents\NetBeansProjects\componente-procesos\target\componente-procesos-1.0.10.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.4:report (report) @ componente-procesos ---
[INFO] Loading execution data file C:\Users\Usuario\Documents\NetBeansProjects\componente-procesos\target\jacoco.exec
[INFO] Analyzed bundle 'componente-procesos' with 14 classes
[INFO]
[INFO] ----------< com.framework:componente-procesos >----------
[INFO] Building componente-procesos 1.0.10
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.6.0.1398:sonar (default-cli) @ componente-procesos ---
[INFO] User cache: C:\Users\Usuario\.sonar\cache
[INFO] SonarQube version: 7.9.1
[INFO] Default locale: "es_CO", source code encoding: "UTF-8"
[WARNING] SonarScanner will require Java 11+ to run starting in SonarQube 8.x
[INFO] Load global settings
[INFO] Load global settings (done) | time=728ms
[INFO] Server id: 02F7F878-AW5hfQnpp0zDeLaf_V6M
[INFO] User cache: C:\Users\Usuario\.sonar\cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=502ms
[INFO] Load/download plugins (done) | time=699ms
[INFO] Process project properties
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=2ms
[INFO] Project key: com.framework:componente-procesos
[INFO] Base dir: C:\Users\Usuario\Documents\NetBeansProjects\componente-procesos
[INFO] Working dir: C:\Users\Usuario\Documents\NetBeansProjects\componente-procesos\target\sonar
[INFO] Load project settings for component key: 'com.framework:componente-procesos'
[INFO] Load project settings for component key: 'com.framework:componente-procesos' (done) | time=507ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=528ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=2224ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 34 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] Quality profile for java: Sonar way
[INFO] ------------- Run sensors on module componente-procesos
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=445ms
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=57ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=21ms
[INFO] Java Main Files AST scan
[INFO] 19 source files to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=451ms
[INFO] 19/19 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=6152ms
[INFO] Java Test Files AST scan
[INFO] 7 source files to be analyzed
[INFO] Java Test Files AST scan (done) | time=947ms
[INFO] 7/7 source files have been analyzed
[INFO] Sensor JavaSquidSensor [java] (done) | time=8676ms
[INFO] Sensor FindBugs Sensor [findbugs]
[INFO] Sensor FindBugs Sensor [findbugs] (done) | time=7ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [C:\Users\Usuario\Documents\NetBeansProjects\componente-procesos\target\surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=270ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 7 source files to be analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=436ms
[INFO] 7/7 source files have been analyzed
[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=87ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=67ms
[INFO] 10 files had no CPD blocks
[INFO] Calculating CPD for 9 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 355ms, dir size=163 KB
[INFO] Analysis report compressed in 218ms, zip size=74 KB
[INFO] Analysis report uploaded in 483ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost?id=com.framework%3Acomponente-procesos
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://localhost/api/ce/task?id=AXCq9AfxRuQxKd0pV_VN
[INFO] Analysis total time: 17.061 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  54.203 s
[INFO] Finished at: 2020-03-05T08:48:05-05:00
[INFO] ------------------------------------------------------------------------

如您所见,我没有从 Sensor JaCoCo XML Report Importer 获得预期的日志。

即使使用正确的覆盖结果生成 jacoco.xml,该结果也不会上传到声纳,分析会抛出 0% 的覆盖结果。

你能帮我在声纳分析中显示覆盖结果吗?

请让我知道我是否可以提供更多信息以便更好地理解问题。

4

1 回答 1

3

在我看来,您没有在 SonarQube 服务器上安装SonarSource JaCoCo插件。打开SonarQube → Administration → Marketplace → Installed并检查是否JaCoCo安装了插件。

SonarQube → 管理 → 市场

于 2020-03-06T16:33:23.623 回答