Sonar / JaCoCo4sbt / Jenkins

2019-03-22 06:54发布

问题:

I would like to know whats the easiest way to plug JaCoCo4sbt's data into Sonar, In Jenkins I have installed Sonar & JaCoCo's plugins. I have also installed JaCoCo's plugin in Sonar.

My sonar-project.properties file contains :

sonar.jacoco.reportPath=target/jacoco/jacoco.exec

And Jenkins's job execute these commands :

sbt jacoco:cover
/opt/sonar-runner/bin/sonar-runner
SBT_OPTS="-Dsbt.log.noformat=true"
sbt clean update compile test doc

For now I don't get any code coverage data into Sonar

回答1:

Do you want to report code coverage on Scala code using the Scala plugin for Sonar (http://docs.codehaus.org/display/SONAR/Scala+Plugin)? Unfortunately it does not yet provide a sensor for code coverage. It's on the roadmap for future versions.

At least jacoco4sbt successfully generates the file jacoco.exec but it is just not picket up by the Scala plugin.



回答2:

You'll need the following properties:

sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=${build.dir}/jacoco.exec

I don't use sbt, but the following is an ANT example:

  • Add ant plugins dynamically at buildtime?

Check the properties file at the end for all the Sonar related stuff.