将Go来源和覆盖范围导入SonarQube

I have a Go project that I would like to import into SonarQube 5.1, using SonarRunner.

I know it's not one of SonarQube's supported languages so I have set the property

sonar.import_unknown_files=true

to accomplish some basic level of import - and it does the job. The project also has code coverage in Cobertura format, generated using https://github.com/axw/gocov/ and https://github.com/AlekSi/gocov-xml.

I have not been successful in getting this XML to import with settings:

sonar.core.codeCoveragePlugin=cobertura
sonar.cobertura.reportPath=coverage.xml

Hence the project appears as a gray box on the Sonar dashboard. Has anyone done something similar and got it working? Is it because Go is an unsupported language?

Many thanks!

Andy

Yes, to my knowledge the SonarQube Cobertura plugin only allows to import coverage reports for Java (and maybe supported JVM based languages).

However, if you are willing to do some transformation on your coverage result file, the Generic Test Coverage plugin might suit your needs.

Since SonarQube 7.9 (July 2019), the go language is officially supported.
That includes code coverage for Go. And it is supported in the community edition!

40 rules for Go were present since SonarQube 6.7 .

But the legacy SonarSource/sonar-go, the Go Analyzer for SonarQube, is now SonarQube LTS) par of SonarSource/slang (SonarSource Language), which is a framework to quickly develop code analyzers for SonarQube.
See MMF-1670 (Migrate Go to SLANG)

SonarGo is relying on the UAST technology developed early in the ideation phase of an unified language to write language parsers, which later led to the creation of SLANG.

In order to unify the technologies we use, reduce the maintain cost, and benefit from more features, we need to migrate the current SonarGO implementation to a GO plugin relying solely on the SLANG framework.

See its Go code coverage SLang issues, in particular: SONARSLANG-399

sonarqube {
  properties {
    property 'sonar.sources', '.'
    property 'sonar.exclusions', '**/*_test.go,**/generate_source.go,**/*_generated.go,**/build/**,**/.gogradle/**'
    property 'sonar.tests', '.'
    property 'sonar.test.inclusions', '**/*_test.go'
    property 'sonar.test.exclusions', '**/build/**,**/.gogradle/**'
    property 'sonar.go.tests.reportPaths', "${project.projectDir}/.gogradle/reports/test-report.out"
    property 'sonar.go.coverage.reportPaths', "${project.projectDir}/.gogradle/reports/coverage/profiles/github.com%2FSonarSource%2Fsonar-go%2Fuast-generator-go.out"
  }
}

SONARSLANG-408 ("[Go] Import Go Cover report") is still in progress though.
(But is only 4 hours old, at the time of writing)