簡體   English   中英

有什么簡單的方法可以在沒有站點:站點的情況下從 Maven 生成 Findbug HTML 報告?

[英]Any easy way to generate a Findbug HTML report from Maven without site:site?

我正在嘗試將 FindBugs 集成到 maven 項目中。 有沒有人有一個示例pom.xml在目標中生成一個簡單的 findbug HTML 報告? 是否可以在無需運行site:site的情況下生成此報告?

Findbugs jar contains 5 XSLT transformations that can be used to convert hard to read XML to easy to read HTML so we can use xml-maven-plugin plugin to execute transformation and here is the configuration:

<plugins>
    <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>
            <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>
</plugins>

要獲取報告,只需執行mvn clean install

上面的代碼片段包含所有 5 種可能的轉換,因此請全部嘗試,希望您能找到您喜歡的一種。

我嘗試使用 maven 3 和 Finbugs 2.0

查看聲納 它是一個開源、獨立的 web 服務,您可以將代碼“提交”到該服務,它會生成漂亮的 HTML 關於各種代碼指標的報告。 它還保留了構建歷史。 最重要的是,您不必修改構建或 pom!

它也有一個 maven 目標: sonar:sonar Jenkins (以前是 Hudson)有一個插件,所以如果你將它用於你的 CI 是完全沒有痛苦的。

看看 - 你不會后悔的!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM