### Sonar 与 Maven 配置 ###
1.下载sonar 包,解压
[下载地址](http://www.sonarqube.org/downloads)
2.修改sonar 配置文件,设置数据库链接
修改 sonar.properties 文件
1.数据库账号、密码
# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=kaifa_user
sonar.jdbc.password=123456
2. 数据库地址
#----- MySQL 5.x
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported.
sonar.jdbc.url=jdbc:mysql://172.16.9.22:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
3.启动sonar
进入: /usr/local/sonarqube-5.1.1/bin/linux-x86-64
执行: ./sonar.sh start
4.修改maven 配置。
方式一:修改项目pom.xml文件
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- EXAMPLE FOR MYSQL -->
<sonar.jdbc.url>jdbc:mysql://172.16.9.22:3306/sonar?useUnicode=true&characterEncoding=utf8</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>kaifa_user</sonar.jdbc.username>
<sonar.jdbc.password>123456</sonar.jdbc.password>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://172.16.9.22:9000</sonar.host.url>
</properties>
</profile>
方式二:修改本地maven setting.xml 文件
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:postgresql://localhost/sonar</sonar.jdbc.url>
<sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>user</sonar.jdbc.username>
<sonar.jdbc.password>password</sonar.jdbc.password>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
5.提交项目
进入项目根路径,执行 mvn sonar:sonar
转载于:https://my.oschina.net/zhenghao/blog/615425