Must-share information (formatted with Markdown):
-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube - 6.7.2
SonarQube gradle plugin version - 3.0
Jacoco gradle plugin version - 0.8.5 -
what are you trying to achieve
We have a multi-module Kotlin Android project.
We are using Azure DevOps for build management.
SonarQube analyzes project and shows all metrics in the dashboard.
But we couldn’t make Sonar import JaCoCo code coverage reports.
It’s always zero percent.
Project SonarQube settings;
In Android project build.gradle (root) addded dependency for sonar gradle plugin
And applied sonar plugin only in root build.gradle with "apply plugin: ‘org.sonarqube’ "
Project JaCoCo settings;
It’s a bit long but we used this guide to setup jacoco in gradle
(‘moduleX’ parts are replaced with real modules in our application)
!!! We didn’t use SonarQube part, Sonar settings are given in build pipeline
At this part we could try JaCoCo in development machine and see that it generates reports in build folder
And main application module (app) has test coverage report for all modules
AzureDevops build pipeline;
1 - In build pipeline added Prepare Analysis Configuration like:
- task: sonarsource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@4
displayName: ‘Prepare analysis on SonarQube’
inputs:
SonarQube: MySonarQubeServiceConnection
scannerMode: Other
extraProperties: |
sonar.exclusions=**/*PackageStrings.kt
sonar.projectKey=(Build.Repository.Name) sonar.projectName=(Build.Repository.Name)
sonar.branch.name = (Build.SourceBranchName) sonar.java.coveragePlugin=jacoco sonar.jacoco.reportPaths=(System.DefaultWorkingDirectory)\app\build\jacoco\testDebugUnitTest.exec
2 - Build gradle step is set like:
- task: Gradle@2
displayName: ‘Build Application’
inputs:
gradleWrapperFile: ‘gradlew’
options: ‘–stacktrace’
tasks: ‘build testDebugUnitTestCoverage’
publishJUnitResults: ‘true’ (Publish to Azure Pipeline is checked)
testResultsFiles: ‘**/build/test-results/testDebugUnitTest/TEST-*.xml’
testRunTitle: ‘Android Unit Test’
sonarQubeRunAnalysis: true
sqGradlePluginVersionChoice: build
checkStyleRunAnalysis: true
pmdRunAnalysis: true
3 - And Publish Quality Gate Results:
- task: sonarsource.sonarqube.291ed61f-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@4
displayName: ‘Publish Quality Gate Result’
- what have you tried so far to achieve this
With given settings in each commit application is tested and test results are generated
(we can see it in AzureDevOps server)
Code is analyzed in SonarQube for quality metrics
But code coverage result is not shown, zero
Gradle command run in build step:
gradlew.bat --stacktrace build testDebugUnitTestCoverage sonarqube -I D:…Long Path…\checkstyle.gradle -I D:…Long Path…\pmd.gradle
We tried
Changing “sonar.java.coveragePlugin=jacoco” to “sonar.core.codeCoveragePlugin=jacoco”
And without this parameter
Before giving .exec file, reportPaths parameter was taking xml report
sonar.coverage.jacoco.xmlReportPaths=$(System.DefaultWorkingDirectory)\app\reports\jacoco\testDebugUnitTestCoverage\testDebugUnitTestCoverage.xml
But nothing changed. Everything worked same (project analyzed without coverage)
Can somebody help me with coverage report import?