我目前正在嘗試使用 gradle 和 bitbucket-pipelines 在我的 SpringBoot 專案中配置 Sonarcloud。但是對于每個 PR 和每個分支,它總是顯示 0% 的行覆寫率。
我已將插件配置添加到我的build.gradle檔案中:
id "org.sonarqube" version "3.4.0.2513"
這是我的bitbucket-pipelines.yml檔案
image: openjdk:11
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- gradle
- sonar
script:
- ./gradlew build sonarqube
artifacts:
- build/libs/**
pipelines: # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
branches:
master:
- step: *build-test-sonarcloud
pull-requests:
'**':
- step: *build-test-sonarcloud
一切似乎都在 Bitbucket 上正確配置,管道為每個 PR 和提交運行,但由于 0% 的覆寫率,它們都失敗了。我期待在 Sonar 和 Bitbucket PR 裝飾上顯示正確的測驗覆寫率。是否缺少任何配置?
uj5u.com熱心網友回復:
雖然 SonarQube 支持報告測驗覆寫率,但它本身不會生成它。您必須使用第三方工具生成它,然后配置 SonarQube 以考慮該第三方工具的結果。
從他們的檔案中:
SonarQube 支持將測驗覆寫率報告作為 Java 專案分析的一部分。但是,SonarQube 本身不會生成覆寫率報告。相反,您必須設定一個 3rd 方工具來生成報告作為構建程序的一部分。
在 3rd 方工具中,SonarQube 直接支持 JaCoCo,所以由于你使用的是 gradle,你只需要在你的build.gradle:
plugins {
id "jacoco" // <-- add here
id "org.sonarqube" version "3.4.0.2513"
}
然后配置 JaCoCo 任務:
jacocoTestReport {
reports {
xml.enabled true
}
}
根據 SonarQube 檔案,它們會自動檢測 JaCoCo 存盤覆寫率報告的默認位置,因此無需進一步配置。
請注意,您還可以使用其他覆寫工具,您不僅限于 JaCoCo,但它應該是最簡單的實作。
有關 Java 測驗覆寫率的檔案可以在此處找到: https ://docs.sonarqube.org/latest/analysis/test-coverage/java-test-coverage/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/521304.html
