Exclude package from Maven-PMD and Findbugs

Suppose, that you need to exclude the package from the maven-pmd-plugin, or you need to exclude the package from findbugs-maven-plugin

maven-pmd-plugin

Pmd definition in project pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>

  <artifactId>maven-pmd-plugin</artifactId>

  <version>${maven.pmd.version}</version>
  <configuration>
    
    <rulesets>
      
      <ruleset>C:/dev/test/pmd-exclude.xml</ruleset>
   
    </rulesets>
  
  </configuration>
  
  <executions>
    
    <execution>
     
      <id>pmd check</id>
      
      <phase>package</phase>
      
      <goals>
       
        <goal>check</goal>
      
      </goals>
    
    </execution>
  
  </executions>

</plugin>

Pmd configuration file pmd-exclude.xml:

<ruleset>
  
  <exclude-pattern>com.example.package/.*</exclude-pattern>

</ruleset>

findbugs-maven-plugin

Findbugs definition in project pom.xml:

<plugin>
  
  <groupId>org.codehaus.mojo</groupId>
  
  <artifactId>findbugs-maven-plugin</artifactId>
  
  <version>${maven.findbugs.version}</version>
  
  <configuration>
    
    <effort>Max</effort>
    
    <threshold>Low</threshold>
    
    <failOnError>true</failOnError>
    
    <excludeFilterFile>C:/dev/test/findbugs-exclude.xml</excludeFilterFile>
  </configuration>
  
  <executions>
    
    <execution>
      
      <id>analyze-compile</id>
      
      <phase>compile</phase>
      
      <goals>
        
        <goal>check</goal>
      
      </goals>
    
    </execution>
  
  </executions>

</plugin>

Findbugs configuration file findbugs-exclude.xml:

<FindBugsFilter>
  <Match>
    <Package name="com.example.package"/>
  </Match>
</FindBugsFilter>
Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *