在Jenkins中配置Findbugs

时间:2016-11-24 11:46:39

标签: maven jenkins pom.xml findbugs

我的目标是在我的项目中为jenkins构建失败,以免FindBugs插件报告错误。为此,我在项目的pom.xml&中集成了FindBugs配置。配置的执行部分在

之下
               <executions>
                    <execution>
                        <id>analyze-compile</id>
                        <phase>compile</phase>
                        <goals><goal>check</goal></goals>
                        <configuration>
                            <threshold>High</threshold>
                        </configuration>
                    </execution>
                </executions>

我从在线资源中找到了上述配置&amp;使用此配置,该项目不会因FindBugs报告的错误而失败。我也试过了下面的其他配置

<xmlOutput>true</xmlOutput>
<configuration>
    <failOnError>${findbugs.failOnError}</failOnError>
    <threshold>High</threshold>
    </configuration>
<executions>
    <execution>
        <id>noFailOnError</id>
            <phase>verify</phase>
        <goals>
            <goal>check</goal>
        </goals>
            <configuration>                                        
               <failOnError>false</failOnError>
        </configuration>
    </execution>
    <execution>
        <id>failOnError</id>
        <phase>install</phase>
        <goals>
            <goal>check</goal>
        </goals>
            <configuration>
                <failOnError>true</failOnError>
            </configuration>
     </execution>
</executions>

有人可以告诉我,如果FindBugs中存在错误,需要使用哪些正确的执行失败?

1 个答案:

答案 0 :(得分:0)

以下是pom.xml中find-bugs的正确配置。它执行以下操作 - 执行FindBugs检查,在验证阶段生成xml报告,将其转换为html&amp;如果在检查期间出现错误

,则构建失败
<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>2.4.0</version>
                <executions>
                    <execution>
                        <id>findbug</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <findbugsXmlOutputDirectory>
                        ${project.build.directory}/findbugs
                    </findbugsXmlOutputDirectory>
                    <failOnError>false</failOnError>
                </configuration>
            </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>install</phase>
                        <goals>
                            <goal>findbugs</goal>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <effort>Max</effort>
                            <threshold>Low</threshold>
                            <failOnError>true</failOnError>
                        </configuration>
                    </execution>
                </executions>
            </plugin>