Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a file for checking in PMD maven pom.xml file?

Tags:

java

maven

pmd

As per what I saw in the documentation it tells to use <exclude-pattern></exclude-pattern> tag for excluding some files (or packages) in the project for checking. But it does not seems to work me. I even tried the maven <excludes></excludes> but it seems to create problem for other part of the project. So what is the ideal way to exclude a file for PMD maven check?

One of the configuration which I used in pom.xml to exclude example is as follows but it does not seems to work :-

<configuration>
    <rulesets>
        <exclude-pattern>.*/example/*.*</exclude-pattern>
        <ruleset>${project.basedir}\ruleset\basic.xml</ruleset>
        <!-- ruleset>${project.basedir}\ruleset\braces.xml</ruleset>
        <ruleset>${project.basedir}\ruleset\design.xml</ruleset>
        <ruleset>${project.basedir}\ruleset\controversial.xml</ruleset>
        <ruleset>${project.basedir}\ruleset\coupling.xml</ruleset>
        <ruleset>${project.basedir}\ruleset\clone.xml</ruleset>
        <ruleset>${project.basedir}\ruleset\comments.xml</ruleset-->
    </rulesets>
</configuration>

You might be seeing that only first rule is being used for checking and other are commented. That is because I am seeing a weird issue in which the build failure happens when only first rule is included but the build passes if all other rules are included along the first one.

like image 382
Siddharth Avatar asked Feb 12 '23 11:02

Siddharth


1 Answers

If you want to exclude files from pmd checks your configuration should look something like this. The exclusions should be under the root of configuration not inside the rulesets tag.

<configuration>
    <excludes>
        <exclude>.*/example/*.*</exclude>
    </excludes>
</configuration>
like image 119
Usman Ismail Avatar answered Feb 13 '23 23:02

Usman Ismail