gpt4 book ai didi

maven - JaCoCo 报道缺失

转载 作者:行者123 更新时间:2023-12-04 02:58:08 26 4
gpt4 key购买 nike

我已经为此工作了几个小时,我尝试过的每一个我在网上找到的解决方案都没有任何区别。

我有一个用 Kotlin 编写的项目。我的 Sonar 服务器上安装了 Kotlin 插件。我正在使用 JaCoCo 插件为 Sonar 生成代码覆盖率报告。

我的项目是多模块的,但只有 1 个子模块有单元测试,所以我在那里定义了我的 JaCoCo 插件。

我也在使用 Surefire 插件。

这是我的 pom.xml 中的属性

<properties>
<sonar.java.binaries>target/classes</sonar.java.binaries>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>kotlin</sonar.language>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.verbose>true</sonar.verbose>
<sonar.jacoco.reportsPath>target</sonar.jacoco.reportsPath>
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>

<surefireArgLine/>
</properties>

这是我的万无一失的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>

这是我的 JaCoCo 插件:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

运行单元测试后,我生成 Sonar 报告,如下所示:
mvn sonar:sonar -Dsonar.projectName=vqs -Dsonar.projectKey=vqs

Sonar 报告没有报道。 sonar report summary

在某个时间点,我正在获取代码覆盖率数据。此时,该项目是一个单独的模块,并且可能没有使用surefire(我记不清了)。

希望有人能看到我的错误并帮助我!

谢谢,
托尼亚

编辑,添加控制台输出:
tohrel@ussd-olm-016438:~/projects/project-name-redacted/vqs-api$ mvn sonar:sonar -Dsonar.projectName=vqs -Dsonar.projectKey=vqs
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Variant Query Service - API 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.4.0.905:sonar (default-cli) @ vqs-api ---
[INFO] User cache: /Users/tohrel/.sonar/cache
[INFO] SonarQube version: 7.2.1
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Publish mode
[INFO] Load global settings
[INFO] Load global settings (done) | time=143ms
[INFO] Server id: AWT2VY5OzSeF07PuEM-H
[INFO] User cache: /Users/tohrel/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=82ms
[INFO] Load/download plugins (done) | time=132ms
[INFO] Loaded core extensions:
[INFO] Process project properties
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=140ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=63ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=618ms
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=19ms
[INFO] Project key: vqs
[INFO] Project base dir: /Users/tohrel/projects/project-name-redacted/vqs-api
[INFO] ------------- Scan vqs
[INFO] Load server rules
[INFO] Load server rules (done) | time=178ms
[INFO] Base dir: /Users/tohrel/projects/project-name-redacted/vqs-api
[INFO] Working dir: /Users/tohrel/projects/project-name-redacted/vqs-api/target/sonar
[INFO] Source paths: src/main
[INFO] Test paths: src/test
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Language is forced to kotlin
[INFO] Index files
[INFO] 254 files indexed
[INFO] Quality profile for kotlin: Sonar way
[INFO] Sensor Kotlin Sensor [kotlin]
[INFO] 208 source files to be analyzed
[INFO] Sensor Kotlin Sensor [kotlin] (done) | time=2693ms
[INFO] 208/208 source files have been analyzed
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=4ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=90ms
[INFO] Sensor CPD Block Indexer
[INFO] Sensor CPD Block Indexer (done) | time=0ms
[INFO] 57 files had no CPD blocks
[INFO] Calculating CPD for 151 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 484ms, dir size=658 KB
[INFO] Analysis reports compressed in 582ms, zip size=444 KB
[INFO] Analysis report generated in /Users/tohrel/projects/project-name-redacted/vqs-api/target/sonar/scanner-report
[INFO] Analysis report uploaded in 27ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=vqs
[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:9000/api/ce/task?id=AWVagYWzPCQMqzjb5q73
[INFO] Task total time: 7.582 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.536 s
[INFO] Finished at: 2018-08-20T20:22:42-07:00
[INFO] Final Memory: 56M/869M
[INFO] ------------------------------------------------------------------------

最佳答案

在上面评论中@Godin 的帮助下(非常感谢),我的代码覆盖率正在工作。

这可能不是唯一的解决方案,但它对我有用。

首先,我从我的 extensions/plugins 目录中删除了官方的 sonar-kotlin-plugin,并添加了这个:https://github.com/arturbosch/sonar-kotlin

其次,我更新了似乎已过时的属性,使其类似于此示例中概述的内容:https://github.com/akquinet/kotlin-calculator/blob/master/pom.xml

属性(摘录)

<properties>
<!-- Sonar configuration -->
<jacoco.report.ut>${project.build.directory}/jacoco-ut.exec</jacoco.report.ut>
<jacoco.report.it>${project.build.directory}/jacoco-it.exec</jacoco.report.it>

<sonar.language>kotlin</sonar.language>
<sonar.sources>src/main/java</sonar.sources>
<sonar.tests>src/test/java</sonar.tests>
<sonar.junit.reportPaths>${project.build.directory}/surefire-reports</sonar.junit.reportPaths>
<sonar.jacoco.reportPaths>${jacoco.report.ut},${jacoco.report.it}</sonar.jacoco.reportPaths>
</properties>

用于surefire、failsafe和jacoco的插件配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${surefireArgLine}</argLine>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>jacoco-agent-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${jacoco.report.ut}</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-agent-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${jacoco.report.it}</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>

关于maven - JaCoCo 报道缺失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51941225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com