代码检查工具有很多findBugs等等
sonar配置:
1、下载sonar 5.5, 解压,运行 sonarqube-5.5\bin\windows-x86-64\StartSonar.bat , 正常可以启动
2、配置 mysql 数据库, 打开conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
创建sonar用户密码以及 sonar数据库,数据库必须InnoDb。
3、配置maven
打开maven的settings.xml文件,profiles节点下添加
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
在maven项目下运行
mvn clean verify sonar:sonar # In some situation you may want to run sonar:sonar goal as a dedicated step. Be sure to use install as first step for multi-module projects
mvn clean install
mvn sonar:sonar # Specify the version of sonar-maven-plugin instead of using the latest. See also 'How to Fix Version of Maven Plugin' below.
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.1:sonar
4、打开 http://localhost:9000/
另外现在人都用git、Jenkins自动化部署了,中间加入Gerrit自动化代码审查就构成了完整的CI系统
参考:
1、使用 Sonar 进行代码质量管理 https://www.ibm.com/developerworks/cn/java/j-lo-sonar/
2、http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven
3、CI 系统搭建:五. GitLab、Gerrit、Jenkins 三者整合 http://blog.csdn.net/tantexian/article/details/42239025