Trouble with SonarQube + Scala: how can I get CPD reports?


I’m using SonarQube 7.4 as provided by sonar-scala-docker with sbt-sonar to generate the reports.

While the defaults are working great, I’d like to get CPD reports for code duplicates as well. I can generate them using sbt-cpd, but the sonar-scanner is not picking up the reports (called from sbt-sonar): “Calculating CPD for 0 files”.
I’m guessing the cpd.xml report is in an unknown location for sonar-scanner (it is at /target/scala-2.11/cpd/cpd.xml).

Has anyone a working setup with sonar-sbt + cpd or can point me into the right direction to solve this? I’d appreciate any help!



There’s no functionality during analysis to pick up external duplications reports. Duplication detection is a basic, on-board function of SonarQube analysis.


So how do I configure sonar-scanner to do duplication detection? Currently it claims that there are no files to analyse for CPD, but I do not find any configuration options to tell CPD what to analyze (only something about excluding files, but that’s not what I need).
Generally, sonar-scanner knows where the source files are, as other reports are computed nicely.

Hi @michi_h57.

This sonar-scala plugin doesn’t feed the “CPD tokens” to SonarQube Scanner. You need to ask the plugin developer to implement it.

Just for reference, an example from sonar-python plugin:

The “magic” here is to initialize a NewCpdTokens like NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); and register the tokens using cpdTokens.addToken(...). Anyway, this should be done in the plugin.

1 Like

Thank you, this was the information i was missing!
I’ll look into the plugin/contact the plugin developer.

Hi Michael,

You can give a try to SonarScala plugin, the Scala analyzer developed by us ( SonarSource :wink: ), it provide code duplication, about 40 rules and import of Scoverage, Scalastyle and Scapegoat reports.
You can install SonarScala from SonarQube marketplace (since v6.7), and it is embedded by default since SonarQube v7.5. More info: SonarScala Documentation.