sbt-cpd icon indicating copy to clipboard operation
sbt-cpd copied to clipboard

It thinks whole file is duplicated

Open hwzhao opened this issue 8 years ago • 8 comments

When I integrate the cpd4sbt 1.2.0, I got the result like

<?xml version="1.0" encoding="utf-8"?>
<pmd-cpd>
   <duplication lines="408" tokens="2626">
      <file line="1" path="D:\program\rrx\app\services\WechatService.scala"/>
      <file line="1" path="D:\program\rrx\app\services\WechatService.scala"/>
      <codefragment><![CDATA[package services
import java.security.MessageDigest
...

It seems whole file is duplicated, and there are all my scala files in the xml file. build.sbt:

lazy val root = (project in file(".")).enablePlugins(PlayScala, CopyPasteDetector, BuildInfoPlugin).
  settings(
    buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
    buildInfoPackage := "tool"
  )

plugins.sbt

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")

addSbtPlugin("de.johoop" % "cpd4sbt" % "1.2.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")

hwzhao avatar Aug 24 '16 03:08 hwzhao

Same problem here

nikayou avatar Feb 13 '17 15:02 nikayou

+1

gurghet avatar Feb 06 '18 16:02 gurghet

I am seeing this problem in sbt-cpd 2.0.0 as well. Files are being compared with themselves. This is what I added to plugins.sbt:

addSbtPlugin("com.github.sbt" % "sbt-cpd" % "2.0.0")

keith-coursera avatar Feb 21 '18 23:02 keith-coursera

while #19 is not merged and release, you can add to your settings as a workaround

CpdKeys.cpdSourceDirectories in Compile := (CpdKeys.cpdSourceDirectories in Compile).value.distinct

jtjeferreira avatar Jun 20 '18 18:06 jtjeferreira

@jtjeferreira add to settings where?

keith-coursera avatar Jun 20 '18 18:06 keith-coursera

@jtjeferreira add to settings where?

you must add that line to your project settings. For example if you use build.sbt add that line to the file...

jtjeferreira avatar Jun 20 '18 20:06 jtjeferreira

@jtjeferreira adding that line to build.sbt gives an error

error: not found: value CpdKeys
CpdKeys.cpdSourceDirectories in Compile := (CpdKeys.cpdSourceDirectories in Compile).value.distinct
^
[error] Type error in expression

keith-coursera avatar Jul 03 '18 23:07 keith-coursera

@keith-coursera you have to import com.github.sbt.cpd.CpdKeys

jtjeferreira avatar Jul 04 '18 09:07 jtjeferreira