在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):aaschmid/gradle-cpd-plugin开源软件地址(OpenSource Url):https://github.com/aaschmid/gradle-cpd-plugin开源编程语言(OpenSource Language):Java 72.6%开源软件介绍(OpenSource Introduction):Gradle CPD pluginTable of ContentsWhat is itA Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD). See also https://plugins.gradle.org/plugin/de.aaschmid.cpd. RequirementsCurrently this plugin requires PMD greater or equal to version 6.1.0 such that Explanation: v2.0 removes deprecated rendering API (= Supported versions
¹: Java version may additionally depend on PMDs version which is might not be properly reflected here. UsageThis plugin is available using either the new Gradle plugins DSL plugins {
id 'de.aaschmid.cpd' version '2.0'
} or the old fashion buildscript block from Maven Central or jCenter. buildscript {
repositories {
// choose your prefered one
mavenCentral()
jcenter()
}
dependencies {
classpath 'de.aaschmid:gradle-cpd-plugin:2.0'
}
}
apply plugin: 'cpd' Attention: The plugins groupId was changed from By default the copy-paste-detection looks at all source code of all projects which at least apply Single module projectIf you have a single module project you just need to make sure that the analyze.dependsOn(cpdCheck) Multi module projectIf the root project of your multi-module project applies the // one single subproject where 'LifecycleBasePlugin' is available
subprojectOne.check.dependsOn(':cpdCheck')
// all subprojects where 'check' task is available (which comes with 'LifecycleBasePlugin')
subprojects {
plugins.withType(LifecycleBasePlugin) { // <- just if 'LifecycleBasePlugin' plugin is not applied to all subprojects
check.dependsOn(rootProject.cpdCheck)
}
} Custom sourceSetsIf your are adding custom sourceSets (even in subProjects), it may occur that you either need to configure ExamplesThis example shows a project where only // optional - settings for every CPD task
cpd {
language = 'cpp'
toolVersion = '6.1.0' // defaults to '6.13.0'; just available for v6.1.0 and higher (see explanation above)
}
// optional - default report is xml and default sources are 'main' and 'test'
cpdCheck {
reports {
text.enabled = true
xml.enabled = false
}
source = sourceSets.main.allJava // only java, groovy and scala classes in 'main' sourceSets
} Note: With v0.2, I have renamed the default task from
Property |
Attribute | Default | Applies for language |
since |
---|---|---|---|
encoding | System default | v0.1 | |
ignoreAnnotations | false |
'java' |
v0.4 |
ignoreFailures | false |
v0.1 | |
ignoreIdentifiers | false |
'java' |
v0.4 |
ignoreLiterals | false |
'java' |
v0.4 |
language | 'java' |
v0.4 | |
minimumTokenCount | 50 |
v0.1 | |
skipDuplicateFiles | false |
v0.5 | |
skipLexicalErrors | false |
v0.5 | |
skipBlocks | true |
'cpp' |
v0.4 |
skipBlocksPattern | '#if 0|#endif' |
'cpp' |
v0.4 |
If a specified language
cannot be found, a fallback mechanism uses net.sourceforge.pmd.cpd.AnyLanguage
instead. This
fallback language does not run ANTLR and therefore also checks duplicates in comments.
For more information about options and their descriptions, see here, and for the available programming languages have a look on CPD documentation. To request more options, please file an issue here.
Additionally, one can configure the following reports for every task analogous to Reporting as for any other reporting plugin. See also the example in Usage section above.
Report | Default | since | Further options and their defaults |
---|---|---|---|
csv | disabled | v0.1 | separator = ',' , includeLineCount = true ² |
text | disabled | v0.1 | lineSeparator = '=====================================================================' , trimLeadingCommonSourceWhitespaces = false |
vs | disabled | v3.1 | encoding = <<System default>> |
xml | enabled | v0.1 | encoding = <<System default>> |
²: Since v3.1 but note that property includeLineCount
is originally named lineCountPerFile
and meaning is inverted which means that
false
shows line count and true
hides it, see
here.
You are very welcome to contribute by providing a patch/pull request.
Please note that running the test cases my take quite long because the acceptance test cases (see
de.aaschmid.gradle.plugins.cpd.test.CpdAcceptanceTest
will download CPD and its dependencies for every version. I recommend to
get these dependencies in your localMaven()
repository as the test cases look there for it first.
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论