sbt / sbt-cpd   2.0.0

Eclipse Public License 1.0 GitHub

Copy & Paste Detector plugin using PMD for sbt.

Scala versions: 2.12 2.10
sbt plugins: 1.0 0.13

sbt-cpd - Copy & Paste Detection using PMD/CPD for sbt

Build Status Codacy Grade sbt 0.13 version sbt 1.0 version pmd version

This is an sbt plugin for duplicate code detection using Copy/Paste Detector (CPD) from the PMD project.

Install the plugin by adding the following to project/plugins.sbt:

addSbtPlugin("com.github.sbt" % "sbt-cpd" % "<version>")

And then execute the plugin with sbt cpd. This will scan your source code under src/main/scala and output a report containing the duplicates to target/scala-2.xx/cpd/cpd.xml.


(see also the CPD documentation)

Key Type Default Description
cpdReportType CpdReportType CpdReportType.XML Selects the output format for the CPD report. Valid types: XML, Simple, CSV & VS
cpdLanguage CpdLanguage CpdLanguage.Scala Language to analyze.1
cpdMaxMemoryInMB Integer 512 Maximum amount of memory to allow for CPD (in MB).
cpdMinimumTokens Integer 100 Minimum number of tokens of potential duplicates.
cpdSourceEncoding String utf-8 Source file encoding.
cpdSourceDirectories Seq (Paths) main source path(s) Paths of the source files to analyze.
cpdOutputType CpdOutputType CpdOutputType.File Selects the output type for the CPD report.2 Valid types: File, Console
cpdTargetPath File Path <cross-target>/cpd Output path for CPD reports.
cpdReportName String (filename) cpd.xml Name of the report file to generate (under cpdTargetPath).
cpdReportFileEncoding String utf-8 Report file encoding.
cpdSkipDuplicateFiles Boolean false Ignore multiple copies of files of the same name and length in comparison.
cpdSkipLexicalErrors Boolean false Skip files which can't be tokenized due to invalid characters instead of aborting.
cpdIgnoreLiterals Boolean false Ignore literal value differences when evaluating a duplicate block.
cpdIgnoreIdentifiers Boolean false Ignore identifier name differences when evaluating a duplicate block.
cpdIgnoreAnnotations Boolean false Ignore language annotations when evaluating a duplicate block.
cpdFailOnDuplicates Boolean false Fail the build if duplicates are detected.
  1. Valid languages:
    • Scala
    • Java
    • C
    • CPP
    • CS
    • CSharp
    • ECMAScript
    • Fortran
    • Go
    • JSP
    • JavaScript
    • Matlab
    • ObjectiveC
    • PHP
    • PLSQ
    • Ruby
    • Swift
  2. If set to CpdOutputType.Console then cpdTargetPath and cpdReportName are ignored.


Many thanks to

for their awesome contributions!


This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at