加入PMD檢查, 以下代碼如果在reporting節點中加入則在mvn site中執行,如果在build節點中加入,則在build的時候自動運行檢查。詳細配置參考pmd插件使用說明
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
加入 checkstyle 檢查,詳細配置參考checkstyle插件使用說明,同樣註意放置在reporting和build節點中的區別(所有報表類插件都要同樣註意):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
</plugin>
加入 simian 的支持,simian是壹個支持代碼相似度檢查的工具,目前有maven插件,也有checkstyle的插件。它不僅可以檢查java,甚至可以支持文本文件的檢查。詳細幫助信息參考這裏。simian 的 maven插件在這裏
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>simian-maven-plugin</artifactId>
<version>1.6.1</version>
</plugin>
</plugins>
...
</build>
加入 jdepend 檢查,詳細配置參考jdepend使用說明
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
加入 findbugz 檢查,詳細配置參考findbugz使用說明,
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0.1</version>
</plugin>
加入javadoc生成,詳細配置參考javadoc usage
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
...
</configuration>
</plugin>
加入 jxr 支持,JXR是壹個生成java代碼交叉引用和源代碼的html格式的工具,詳細配置信息參考jxr usage。註意,jxr沒有必要在build階段運行。
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</reporting>
加入 Cobertura 支持,它是壹個代碼覆蓋率工具,可以用來評估具有相應測試的源代碼的比率。詳細幫助在這裏。另外壹個功能相似的軟件是EMMA,詳細的幫助在這裏。兩個產品的比較文章在這裏,個人傾向於都要用,因為給出的指標不壹樣,都有參考作用。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<check>
<branchRate>85</branchRate>
<lineRate>85</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>85</totalBranchRate>
<totalLineRate>85</totalLineRate>
<packageLineRate>85</packageLineRate>
<packageBranchRate>85</packageBranchRate>
<regexes>
<regex>
<pattern>com.example.reallyimportant.*</pattern>
<branchRate>90</branchRate>
<lineRate>80</lineRate>
</regex>
<regex>
<pattern>com.example.boringcode.*</pattern>
<branchRate>40</branchRate>
<lineRate>30</lineRate>
</regex>
</regexes>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<reporting>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3-SNAPSHOT</version>
</plugin>
...
</plugins>
...
</reporting>
添加 javaNCSS 插件,它是壹個java代碼的度量工具,詳細參考在這裏。
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
</plugins>
</reporting>