Sonar-scanner Properties

The plugin exposes the following properties which can be passed to sonar-scanner when running an analysis:

  • sonar.sources - Scala source directory relative to the root of your project (usually src/main/scala)
  • sonar.tests (optional) - Scala tests directory relative to the root of your project (usually src/test/scala)
  • sonar.junit.reportPaths (optional) - relative path to the directory containing unit test execution reports in Surefire XML format (defaults to target/test-reports); those reports get generated automatically by sbt and Gradle (Gradle outputs those in build/test-results/test), for Maven see the examples on how to configure the Surefire plugin
  • sonar.scala.version (optional) - defines the version of Scala used in your project (requires the {major}.{minor} versions and the patch version is ignored, defaults to 2.12)
  • sonar.scala.scoverage.reportPath (optional) - relative path to the scoverage report (defaults to target/scala-${sonar.scala.version}/scoverage-report/scoverage.xml)
  • sonar.scala.scoverage.disable (optional) - disables the Scoverage sensor from being executed on your sources (defaults to false)
  • sonar.scala.scalastyle.disable (optional) - disables the Scalastyle sensor from being executed on your sources (defaults to false)
  • sonar.scala.scapegoat.reportPath (optional) - relative path to the scapegoat report (defaults to target/scala-${sonar.scala.version}/scapegoat-report/scapegoat.xml)
  • sonar.scala.scapegoat.disable (optional) - disables the Scapegoat sensor from being executed on your sources (defaults to false)

See an example usage:

sonar-scanner \
-Dsonar.host.url=https://your-sonarqube
-Dsonar.projectName=test \
-Dsonar.projectKey=test \
-Dsonar.sources=src/main/scala \
-Dsonar.tests=src/test/scala \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.scala.version=2.12 \
-Dsonar.scoverage.reportPath=target/scala-2.12/scoverage-report/scoverage.xml \
-Dsonar.scapegoat.reportPath=target/scala-2.12/scapegoat-report/scapegoat.xml

Or simply run sbt -Dsonar.host.url=https://your-sonarqube sonarScan if you use the sbt-sonar sbt plugin. See the next page for more details on sbt-sonar.

Debug mode

To run sonar-scala in a debug mode, set the sonar.verbose property to true, e.g.

sbt \
-Dsonar.host.url=https://your-sonarqube \
-Dsonar.verbose=true \
sonarScan