I am using Sonarcloud with gradle plugin .
I was able to run Sonarqube analysis using gradle and push the result to Sonarcloud but for some reason the sonar plugin is not pushing the jacoco code coverage report to Sonar cloud .
I cloud see the code coverage report generated in the folder specified but sonarqube plugin refuses to push to sonar cloud
Hello,
New user of SonarCloud here.
I am trying to do the same thing, and cannot seem to get any code coverage for my kotlin project to sonarcloud.
I am running on gradle 5.6.3, kotlin 1.3.50, and junit 5 tests
plugins {
jacoco
id("org.sonarqube") version "2.7.1"
}
I’m trying to reproduce your scenario but I don’t know what you mean by “Jacoco coverage: 99%”. Where / how do you see that? Can you please clarify?
Since you mention Junit5, I’m wondering if you’re falling into the pitfall of missing this in your build.gradle:
test {
useJUnitPlatform()
}
Lastly, it will help if you can include the output of your ./gradle run with --info flag activated. (You might want to anonymize sensitive parts, if any.)
We generate both xml and html reports using jacoco
looking at the coverage results in the HTML reports shows that we have an overall coverage of 99%
however the sonarcloud ui shows 0% coverage.
here is the gradle output
Gradle Test Executor 1 finished executing tests.
> Task :test
Finished generating test XML results (0.032 secs) into: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test
Generating HTML test report...
Finished generating test html results (0.041 secs) into: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/reports/tests/test
:test (Thread[Daemon worker,5,main]) completed. Took 12.618 secs.
:check (Thread[Daemon worker,5,main]) started.
> Task :check
Skipping task ':check' as it has no actions.
:check (Thread[Daemon worker,5,main]) completed. Took 0.0 secs.
:build (Thread[Daemon worker,5,main]) started.
> Task :build
Skipping task ':build' as it has no actions.
:build (Thread[Daemon worker,5,main]) completed. Took 0.0 secs.
:jacocoTestReport (Thread[Daemon worker,5,main]) started.
> Task :jacocoTestReport
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.ant/0.8.5/org.jacoco.ant-0.8.5.pom to /tmp/gradle_download6487116482281690675bin
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.report/0.8.5/org.jacoco.report-0.8.5.pom to /tmp/gradle_download13205387547010241801bin
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.core/0.8.5/org.jacoco.core-0.8.5.pom to /tmp/gradle_download13059259236100536318bin
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.pom to /tmp/gradle_download16411083068679993892bin
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.pom to /tmp/gradle_download10514684586287393241bin
Found locally available resource with matching checksum: [https://jcenter.bintray.com/org/ow2/asm/asm/7.2/asm-7.2.pom, /root/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/7.2/16cc249bcaaeb17f49622826bc3e17518698088/asm-7.2.pom]
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.pom to /tmp/gradle_download6426576549753437902bin
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar to /tmp/gradle_download15672556594971103855bin
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.report/0.8.5/org.jacoco.report-0.8.5.jar to /tmp/gradle_download12502976899567260474bin
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.ant/0.8.5/org.jacoco.ant-0.8.5.jar to /tmp/gradle_download5110282490867444160bin
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar to /tmp/gradle_download17697377744444274491bin
Found locally available resource with matching checksum: [https://jcenter.bintray.com/org/ow2/asm/asm/7.2/asm-7.2.jar, /root/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/7.2/fa637eb67eb7628c915d73762b681ae7ff0b9731/asm-7.2.jar]
Downloading https://jcenter.bintray.com/org/jacoco/org.jacoco.core/0.8.5/org.jacoco.core-0.8.5.jar to /tmp/gradle_download10537703451748331368bin
Downloading https://jcenter.bintray.com/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar to /tmp/gradle_download12932030430747347270bin
Caching disabled for task ':jacocoTestReport' because:
Build cache is disabled
Task ':jacocoTestReport' is not up-to-date because:
No history is available.
[ant:jacocoReport] Loading execution data file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/jacoco/test.exec
[ant:jacocoReport] Writing bundle 'myservice-service' with 0 classes
:jacocoTestReport (Thread[Daemon worker,5,main]) completed. Took 2.165 secs.
:sonarqube (Thread[Daemon worker,5,main]) started.
> Task :sonarqube
Caching disabled for task ':sonarqube' because:
Build cache is disabled
Task ':sonarqube' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Bitbucket Cloud Pipelines detected
User cache: /root/.sonar/cache
Default locale: "en", source code encoding: "UTF-8"
Load global settings
Load global settings (done) | time=573ms
Server id: 74E9293D-AWHW8ct9-T_TB3XqouNu
User cache: /root/.sonar/cache
Load/download plugins
Load plugins index
Load plugins index (done) | time=131ms
Load/download plugins (done) | time=364ms
Loaded core extensions: developer-scanner
Detected project key 'myorg_myservice-service' from 'Bitbucket Cloud Pipelines'
Detected organization key 'myorg' from 'Bitbucket Cloud Pipelines'
Process project properties
Execute project builders
Execute project builders (done) | time=3ms
Project key: myorg_myservice-service
Base dir: /opt/atlassian/$BB_AUTH_USERs/agent/build
Working dir: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/sonar
Load project settings for component key: 'myorg_myservice-service'
Load project settings for component key: 'myorg_myservice-service' (done) | time=140ms
Load project branches
Load project branches (done) | time=112ms
Load projects for organization 'myorg'
Load projects for organization 'myorg' (done) | time=1168ms
Load project pull requests
Load project pull requests (done) | time=98ms
Load branch configuration
Detected analysis for branch 'feature/sonarcloud'
Detected Bitbucket Pipelines
Auto-configuring branch feature/sonarcloud
Load branch configuration (done) | time=3ms
Load quality profiles
Load quality profiles (done) | time=148ms
Detected Bitbucket Pipelines
Load active rules
Load active rules (done) | time=4262ms
Organization key: myorg
Branch name: feature/sonarcloud, type: short living
SCM collecting changed files in the branch
SCM collecting changed files in the branch (done) | time=230ms
Indexing files...
Project configuration:
41 files indexed
> Task :sonarqube
0 files ignored because of scm ignore settings
Quality profile for kotlin: Sonar way
------------- Run sensors on module myservice-service
Load metrics repository
Load metrics repository (done) | time=103ms
Sensor JavaXmlSensor [java]
Sensor JavaXmlSensor [java] (done) | time=2ms
Sensor HTML [web]
Sensor HTML [web] (done) | time=5ms
Sensor JaCoCo XML Report Importer [jacoco]
Sensor JaCoCo XML Report Importer [jacoco] (done) | time=10ms
Sensor Kotlin Sensor [kotlin]
24 source files to be analyzed
Sensor Kotlin Sensor [kotlin] (done) | time=1280ms
Sensor JavaSecuritySensor [security]
24/24 source files have been analyzed
CPD calculation finished
> Task :sonarqube
Reading type hierarchy from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/sonar/ucfg2/java
Read 0 type definitions
Reading UCFGs from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/sonar/ucfg2/java
No UCFGs have been included for analysis.
Sensor JavaSecuritySensor [security] (done) | time=5ms
Sensor CSharpSecuritySensor [security]
Reading type hierarchy from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/ucfg_cs2
Read 0 type definitions
Reading UCFGs from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/ucfg_cs2
No UCFGs have been included for analysis.
Sensor CSharpSecuritySensor [security] (done) | time=1ms
Sensor PhpSecuritySensor [security]
Reading type hierarchy from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/sonar/ucfg2/php
Read 0 type definitions
Reading UCFGs from: /opt/atlassian/$BB_AUTH_USERs/agent/build/build/sonar/ucfg2/php
No UCFGs have been included for analysis.
Sensor PhpSecuritySensor [security] (done) | time=0ms
------------- Run sensors on project
Sensor Zero Coverage Sensor
Sensor Zero Coverage Sensor (done) | time=17ms
12 files had no CPD blocks
Calculating CPD for 12 files
SCM writing changed lines
SCM writing changed lines (done) | time=3ms
Analysis report generated in 101ms, dir size=155 KB
Analysis report compressed in 38ms, zip size=45 KB
Analysis report uploaded in 280ms
ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=myorg_myservice-service&branch=feature%2Fsonarcloud&resolved=false
Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
More about the report processing at https://sonarcloud.io/api/ce/task?id=AW5lr0V-bQ8XVloyjF-S
Analysis total time: 12.019 s
:sonarqube (Thread[Daemon worker,5,main]) completed. Took 15.943 secs.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 2m 7s
22 actionable tasks: 22 executed
Created user preferences directory.
You already have a 'gradle' cache so we won't create it again
You already have a 'gradlewrapper' cache so we won't create it again
You already have a 'sonar' cache so we won't create it again
Cache "gradle": Skipping upload for existing cache
Cache "gradlewrapper": Skipping upload for existing cache
Cache "sonar": Skipping upload for existing cache
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, surefire-reports] down to a depth of 4
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.SqlUtilsTest.xml
Located test suite containing 1 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.services.grpc.GrpcSecuritiesProcessTest.xml
Located test suite containing 11 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.services.myserviceServiceTest.xml
Located test suite containing 15 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.services.grpc.GrpcCompaniesProcessTest.xml
Located test suite containing 8 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.myserviceReferenceDaoTest.xml
Located test suite containing 6 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.services.grpc.GrpcReferenceProcessTest.xml
Located test suite containing 11 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.BaseDaoTest.xml
Located test suite containing 2 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.myserviceCompanyDaoTest.xml
Located test suite containing 6 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.repository.domain.DomainObjectTest.xml
Located test suite containing 7 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.dao.myserviceSecurityDaoTest.xml
Located test suite containing 4 tests, with 0 failures and 0 errors.
Found matching test report file /opt/atlassian/$BB_AUTH_USERs/agent/build/build/test-results/test/TEST-com.myorg.myservice.test.MvcTest.xml
Located test suite containing 1 tests, with 0 failures and 0 errors.
Finished scanning for test reports. Found 11 test report files.
Merged test suites, total number tests is 72, with 0 failures and 0 errors.
Uploading test results
Finished uploading test results.
It turned out to be an issue in bitbucket pipelines:
having ./gradlew clean build jacocoTestReport sonarqube on the same step yields 0 classes in the report
(unlike on my local machine)
I had to create a separate step for jacocoTestReport sonarqube to solve my issue.