我目前正在使用具有良好覆蓋率的gradle multi模塊java項目和sonarqube 6.2與sonarJava插件4.10.0.1026。我正在使用Gradle 4.0.1,sonarqube插件2.5和jacoco 0.7.9!代碼是java 8.Gradle多模塊項目中sonarqube 6.2的覆蓋率計算錯誤
由於API驅動的開發,API測試在API項目中被編寫爲抽象測試,並從提供測試構造函數的實現項目中調用。
在分析sonarqube服務器上的項目時,實施項目的覆蓋率被正確測量,但IMPL項目測試中包含的API項目覆蓋率爲0.0%。這些項目的覆蓋率結果被忽略。
當簡單地使用jacoco插件時,我能夠得到相同的行爲。之後做一些研究,我發現一個解決方案,以獲得適當的jacoco報道:
task codeCoverageReport(type: JacocoReport) {
description "Creates a unified JaCoCo test report for the project."
// Gather execution data from all subprojects
// (change this if you e.g. want to calculate unit test/integration test
coverage separately)
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
// Add all relevant sourcesets from the subprojects
subprojects.each {
sourceSets it.sourceSets.main
}
reports {
xml.enabled true
html.enabled true
html.destination file("${buildDir}/reports/jacoco")
csv.enabled false
}
}
// always run the tests before generating the report
codeCoverageReport.dependsOn {
subprojects*.test
}
我現在的結果如下:
JaCoCo:
- JaCoCo(codeCoverageReport任務)
- 73%指導覆蓋範圍
- 91%分支覆蓋範圍
- 聲納
- 43.1%線Coverage(僅〜30%線在計算中考慮!)
- 82.1%條件覆蓋(僅〜覆蓋20%的條件!)
因此聲納的覆蓋率結果是不可用的。我讀過一篇帖子,宣佈「sonar.jacoco.reportPaths」參數以sonar 6.2開頭,我認爲java-analyzer 4.4或者某些東西。像那樣。將此參數添加到我的gradle構建腳本時,腳本不再編譯。當通過聲納項目管理將jacoco.exe文件添加到聲納時,沒有任何更改。
如果能夠管理聲納來計算正確的覆蓋範圍,那將是非常好的選擇。
有一個[JacocoMerge](https://docs.gradle.org/4.0/dsl/org.gradle.testing.jacoco.tasks.JacocoMerge.html)任務可以合併將多個執行文件合併爲一個 –
在接下來的幾天內會再次嘗試。第一次測試的最後幾天沒有正常工作。 –
有一個例子[這裏](https://github.com/gradle/gradle/blob/28fa962a330ea6085ea324381eec4f31dcf92d1c/subprojects/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoPluginMultiVersionIntegrationTest.groovy#L142)在Gradle測試中,它將單個項目中的多個「測試」任務合併並生成合並報告。您可以調整您的多項目設置 –