<properties> <!--其餘參數--> ... <!--插件版本--> <pmd.version>3.8</pmd.version> <findbugs.version>3.0.5</findbugs.version> </properties>
<build> <plugins> <!--其餘插件--> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>${findbugs.version}</version> <!--在compile後自動執行check,必須事先compile編譯過,否則findbugs不能發現bug--> <!--<executions>--> <!--<execution>--> <!--<id>findbugs-check</id>--> <!--<phase>compile</phase>--> <!--<goals>--> <!--<goal>check</goal>--> <!--</goals>--> <!--</execution>--> <!--</executions>--> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>${pmd.version}</version> <configuration> <sourceEncoding>utf-8</sourceEncoding> <minimumTokens>100</minimumTokens> <targetJdk>${maven.compiler.target}</targetJdk> <excludes> <!--<exclude>**/*Bean.java</exclude>--> <!--<exclude>**/generated/*.java</exclude>--> </excludes> <excludeRoots> <!--<excludeRoot>target/generated-sources/stubs</excludeRoot>--> </excludeRoots> </configuration> <!--在clean後自動執行check--> <!--<executions>--> <!--<execution>--> <!--<id>pmd-check</id>--> <!--<phase>clean</phase>--> <!--<goals>--> <!--<goal>check</goal>--> <!--</goals>--> <!--</execution>--> <!--</executions>--> </plugin> </plugins> </build>
注:當項目經過Jenkins構建時,能夠把註釋掉的<executions>解註釋,這樣會在構建時的clean階段後經過PMD靜態分析源碼是否符合規範,而後在compile階段後經過FindBugs檢查Bug。若是發現問題則會報錯致使本次構建失敗。 java
<!--執行mvn clean compile site,會在target目錄建立site目錄生成項目網頁報告--> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>${pmd.version}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>${findbugs.version}</version> </plugin> </plugins> </reporting>