Skip to content
/ sbt-cpd Public

Copy & Paste Detector plugin using PMD for sbt.

License

Notifications You must be signed in to change notification settings

sbt/sbt-cpd

Repository files navigation

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.

Settings

(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.

Contributors

Many thanks to

for their awesome contributions!

License

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 http://www.eclipse.org/legal/epl-v10.html