Is there a way to tell PMD to ignore checking parts of code for duplication?
For example, can I do something like this:
// CPD-Ignore-On
...
// CPD-Ignore-Off
Currently I have PMD set up like this using Maven, but don't see any arguments that would like me do what I want unless I am missing something.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<minimumTokens>40</minimumTokens>
<targetJdk>1.5</targetJdk>
<ignoreIdentifiers>true</ignoreIdentifiers>
<ignoreLiterals>true</ignoreLiterals>
</configuration>
</plugin>
Duplicate code can be hard to find, especially in a large project. But PMD's Copy/Paste Detector (CPD) can find it for you! CPD works with Java, JSP, C/C++, C#, Go, Kotlin, Ruby, Swift and many more languages. It can be used via command-line, or via an Ant task.
Don't Repeat Yourself (DRY): Using DRY or Do not Repeat Yourself principle, you make sure that you stay away from duplicate code as often as you can. Rather you replace the duplicate code with abstractions or use data normalization. To reduce duplicity in a function, one can use loops and trees.
After digging around enough, I finally came across it.
By adding the annotations @SuppressWarnings("CPD-START")
and @SuppressWarnings("CPD-END")
all code within will be ignored by CPD - thus you can avoid false positives.
Source - http://pmd.sourceforge.net/pmd-5.0.5/cpd-usage.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With