Reputation: 5031
I have maven project with multiple modules, the structure is like this:
/myProject
pom.xml
exclude-cpd.properties
-- module1
pom.xml
exclude-cpd.properties
-- module2
pom.xml
exclude-cpd.properties
in my parent pom.xml i added pmd plugin:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.12.0</version>
<configuration>
<rulesets>
<ruleset>pmd_ruleset.xml</ruleset>
</rulesets>
<minimumTokens>80</minimumTokens>
<includeTests>true</includeTests>
<excludeFromFailureFile>exclude-cpd.properties</excludeFromFailureFile>
<printFailingErrors>true</printFailingErrors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
and in exclude-cpd.properties i include all files that i want to exclude from cpd-check as comma separated strings.
but as I run mvn clean compile
, it still scan those excluded files and complained about duplication. seems that excludeFromFailureFile
doesn't work at all, I eventually had to use excludes
to exclude files from pmd check and cpd check but that's not ideal. anyone knows how to get excludeFromFailureFile
working?
working pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.12.0</version>
<configuration>
<rulesets>
<ruleset>pmd_ruleset.xml</ruleset>
</rulesets>
<minimumTokens>80</minimumTokens>
<includeTests>true</includeTests>
<excludes>
<exclude>**/XyzService*.java</exclude>
</excludes>
<printFailingErrors>true</printFailingErrors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Upvotes: 4
Views: 1848
Reputation: 31
The other good idea is using @SuppressWarnings("CPD-START") and @SuppressWarnings("CPD-END") to ignore all java code within these two annotations by CPD, e.g.:
...
//enable suppression (start)
@SuppressWarnings("CPD-START")
public Object shouldBeIgnoredFromHere(String any) throws Exception {
// any code here will be ignored for the duplication detection
}
...
//disable suppression (end)
@SuppressWarnings("CPD-END)
public void shouldBeIgnoredToHere() {
}
...
Read suppression chapter: https://pmd.sourceforge.io/pmd-5.0.5/cpd-usage.html
Upvotes: 1
Reputation: 4150
I think you are misunderstanding the flags.
The excludeFromFailureFile
is literally that: do not fail the build if violations are reported on these files. The files are still analyzed, but if only those files and no other have violations, the build still passes (if other files have violations the build still fails). This is not even a PMD feature, but something the Maven plugin bakes in.
It's not an "exclude from analysis", to do that you have the excludes
configuration as you use on your second example.
Upvotes: 2