Search code examples
javaxmlmavenfindbugshtml-reports-jenkins

Findbugs plugin configuration in maven pom.xml


My goal is to execute findbugs on a maven project -> generate xml -> convert xml to html & finally fail build if there are HIGH priority FindBugs warnings. Below is the plugin configuration configuration in pom.xml I have configured

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.3</version>
                <executions>
                    <execution>
                        <id>noFailOnError</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <failOnError>false</failOnError>
                            <xmlOutput>true</xmlOutput>
                            <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>transform</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <transformationSets>
                        <transformationSet>
                            <dir>${project.build.directory}/findbugs</dir>
                            <outputDir>${project.build.directory}/findbugs</outputDir>
                            <stylesheet>fancy-hist.xsl</stylesheet>
                            <!--<stylesheet>default.xsl</stylesheet> -->
                            <!--<stylesheet>plain.xsl</stylesheet> -->
                            <!--<stylesheet>fancy.xsl</stylesheet> -->
                            <!--<stylesheet>summary.xsl</stylesheet> -->
                            <fileMappers>
                                <fileMapper
                                    implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>.html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                    </transformationSets>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.google.code.findbugs</groupId>
                        <artifactId>findbugs</artifactId>
                        <version>2.0.0</version>
                    </dependency>
                </dependencies>
            </plugin>


            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.3</version>
                <executions>
                    <execution>
                        <id>failing-on-high</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>findbugs</goal>
                        </goals>
                        <configuration>
                            <failOnError>true</failOnError>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

My problem is that html transformation is not happening stating that

[WARNING] No files found for transformation by stylesheet fancy-hist.xsl

Can the pom.xml correctness be verified & also can someone help me with the reason on why html tansformation is not happening ?


Solution

  • The issue with the above plugin configuration is that failing-on-high is configured during the verify phase rather than install phase. So in case of build error in verify phase, no output xml is generated because of which the output xml was not found. This was fixed by changing it to install

    <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.3</version>
                    <executions>
                        <execution>
                            <id>failing-on-high</id>
                            <phase>install</phase>
                            <goals>
                                <goal>findbugs</goal>
                            </goals>
                            <configuration>
                                <failOnError>true</failOnError>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>