PMD CPD has no such option, so short of filing a feature request, it is not possible.
However, you could use annotations for suppression as described in the CPD docs:
//enable suppression
@SuppressWarnings("CPD-START")
public Object someMethod(int x) throws Exception {
// any code here will be ignored for the duplication detection
}
//disable suppression
@SuppressWarnings("CPD-END")
public void nextMethod() {
}
Personally, I don't like this syntax very much, because it makes you annotate completely unrelated methods. nextMethod()
has nothing to do with someMethod()
, but still gets the CPD-END
annotation. But it may stil be better than putting a whole lot of //NOPMD
comments. It also excludes the method only for CPD, but not for other PMD detectors, as //NOPMD
would.
Your initial wish of not putting information for analyis tools into the code is understandable. However, when I think about it, the annotations and comments do say something about the code, so having the code's meta information in the source is not such a bad thing. If you still don't like it, consider using SonarQube or some other tool with a database behind it.