We are running SonarQube v7.9.2 and SonarScanner v4.2.0.1873.
As far as I can tell I have modeled our build process after the documentation, but I continue to see 0% code coverage for all of my Go projects. At build time we run the following command to run tests and output the coverage file:
go test "./..." -coverprofile="coverage.out"
I’ve verified the coverage.out file is created in the root of the build workspace. Next we run the sonar scanner CLI. Here are the contents of the sonar.properties file in the root of the project:
sonar.host.url=https://sonar.xxxxxx.com
sonar.projectKey=fileIngestionService
sonar.sources=/var/jenkins_home/jobs/fileIngestionService/workspace
sonar.tests=/var/jenkins_home/jobs/fileIngestionService/workspace
sonar.exclusions=**/vendor/**
sonar.test.inclusions=**/*_test.go,**/testdata/**
sonar.go.tests.reportPaths=coverage.out
sonar.projectVersion=v2.8.3
And we simply run
/opt/sonar-scanner/bin/sonar-scanner
When the sonar scan runs, it appears to run successfully. I’ve tested changing the sonar.go.tests.reportPaths in the properties file to a different file name to ensure I get an error, which I do. When I change it back to the coverage.out file I do not get an error, so it appears sonar scanner is finding the coverage file.
Similarly I’ve also run the native go tool to verify that we do indeed see proper code coverage from the coverage.out. I’ve run:
go tool cover -func="coverage.out"
This outputs a bunch of info, but ultimately reports something like 53% overall code coverage, so I know the coverage info in the file seems correct.
On my SonarQube project; however, I see overall coverage at 0% with 927 lines to cover and 927 uncovered lines.
What am I doing wrong?
Here is a log of my sonar scanner output:
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /var/jenkins_home/jobs/fileIngestionService/workspace/sonar-project.properties
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 3.13.0-170-generic amd64
INFO: User cache: /root/.sonar/cache
INFO: SonarQube server 7.9.2
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=195ms
INFO: Server id: DACD8EC7-AWYhBymxG4coyY0aj8Nh
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=59ms
INFO: Load/download plugins (done) | time=106ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: fileIngestionService
INFO: Base dir: /var/jenkins_home/jobs/fileIngestionService/workspace
INFO: Working dir: /var/jenkins_home/jobs/fileIngestionService/workspace/.scannerwork
INFO: Load project settings for component key: 'fileIngestionService'
INFO: Load project settings for component key: 'fileIngestionService' (done) | time=22ms
INFO: Load project branches
INFO: Load project branches (done) | time=38ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=20ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=40ms
INFO: Load active rules
INFO: Load active rules (done) | time=575ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: **/vendor/**, **/*_test.go, **/testdata/**
INFO: Included tests: **/*_test.go, **/testdata/**
INFO: 73 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for go: Sonar way
INFO: ------------- Run sensors on module fileIngestionService
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=30ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/root/.sonar/cache/866bb1adbf016ea515620f1aaa15ec53/sonar-javascript-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor SonarGo [go]
INFO: Load project repositories
INFO: Load project repositories (done) | time=22ms
INFO: Sensor SonarGo [go] (done) | time=1171ms
INFO: Sensor Go Unit Test Report [go]
INFO: Sensor Go Unit Test Report [go] (done) | time=9ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=3ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=51ms
INFO: Calculating CPD for 24 files
INFO: CPD calculation finished
INFO: Analysis report generated in 215ms, dir size=241 KB
INFO: Analysis report compressed in 97ms, zip size=98 KB
INFO: Analysis report uploaded in 147ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonar.xxxxxxxx.com/dashboard?id=fileIngestionService
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 https://sonar.xxxxxxxx.com/api/ce/task?id=AW_4IhScs7vvXAmqlOZq
INFO: Analysis total time: 4.757 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 6.179s
INFO: Final Memory: 11M/44M
INFO: ------------------------------------------------------------------------