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.
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.
You can give a try to SonarScala plugin, the Scala analyzer developed by us ( SonarSource ), 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.