项目质量保证凶器 - Sonar
项目质量保证利器 - Sonar
下载开源工具包:
Sonar :
http://www.sonarsource.org/downloads/
Mysql DB :
http://dev.mysql.com/downloads/
需要配置Sonar的数据
- 找到Sonar配置文件: %SONAR_HOME%/conf/sonar.properties
-
修改配置参数,指向既有的DB : URL + Username + Password
-
启动Sonar
配置Sonar插件
POM文件中加入如下配置片段
<pluginRepositories> <pluginRepository> <id>sonar</id> <name>Sonar Plugin</name> <url>https://nexus.codehaus.org/content/groups/snapshots-group/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>
注意: 需要设置snapshots的enabled为true,因为,默认使用的是false;
添加sonar plugin依赖:
<dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.0-SNAPSHOT</version> </dependency>
运行Maven命令
mvn clean sonar:sonar -Dsonar.host.url=http://localhost:9000/ -Dsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar -Dsonar.jdbc.driverClassName=com.mysql.jdbc.Driver -Dsonar.jdbc.username=root -Dsonar.jdbc.password=exigen
查看Sonar的运行结果
登录: http://localhost:9000/
==============================================
Mysql 数据配置其他机器登陆访问,可以会遇到权限问题,具体详细步骤:
-
新建一个Sonar专用的DB - create database sonar;
-
创建一个可以其他机器可以访问的账号 - GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;