Findbugs Maven plugin - findbugs-exclude with multiple projects

Viewed 11965

I've got a multiple project setup, using Maven and the Findbugs plugin. I need to exclude some files in one of the child projects, so I added it to findbugs-exclude.xml. That works when I build in the subproject.

My issue comes when I try to build at top level. Maven is not finding the findbugs-exclude.xml in the subproject. So it doesn't ignore my errors and fails because of them. I can put my findbugs-exclude.xml in the top level directory, and the exclusion works. But that's polluting the top level, and would not be looked upon favorably.

Is there a way to get the Maven plugin to use the findbugs-exclude.xml file from a subdirectory? Preferably with little to no change at the top level?

5 Answers

I'm using spotbugs cause findbugs is deprecated and no longer support. I had the same issue in my project.

My maven project multi-module structure is similar to this:

parent-module:
  |
  -- sub-module-1
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- sub-module-2
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- sub-module-n
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- exclude-filter.xml
  |
  --pom.xml

The spotbugs configuration of parent-module:

...
<build>
    ...    
    <plugins>
        ...
        <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>4.0.0</version>
            <dependencies>
                <dependency>
                    <groupId>com.github.spotbugs</groupId>
                    <artifactId>spotbugs</artifactId>
                    <version>4.0.2</version>
                </dependency>
            </dependencies>
            <configuration>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <includeTests>true</includeTests>
                <xmlOutput>true</xmlOutput>
                <excludeFilterFile>exclude-filter.xml</excludeFilterFile>
            </configuration>
            <executions>
                <execution>
                    <id>analyze-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
...
</build>
...

No you can do mvn test-compile from parent-project or any sub-project and it will check by spotbugs for source and test-sources code issues.

Consider example: https://github.com/koresmosto/mif

Related