5、 sonar安装和配置
到http://www.sonarqube.org/downloads/下载sonar,如:sonar-3.7.4.zip
解压sonar-3.7.4.zip,到任意路径,如:d:\sonar-3.7.4
1) 安装mysql数据库
创建数据库和账号
mysql>CREATE DATABASE sonar CHARACTERSET utf8 COLLATE utf8_general_ci;
mysql>grant all on sonar.* to sonar@'%'identified by 'sonar';
mysql>grant all on sonar.* tosonar@localhost> mysql>flush privileges;
2) 修改sonar配置文件
修改D:\sonar-3.7.4\conf\sonar.properties,注释掉原有的jdbc行,开启mysql的jdbc连接行:
#----- Credentials
# Permissions to create tables and indexesmust be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
#----- Embedded database H2
# Note : it does not accept connectionsfrom remote hosts, so the
# SonarQube server and the maven pluginmust be executed on the same host.
# Comment the following line to deactivatethe default embedded database.
# sonar.jdbc.url: jdbc:h2:tcp://localhost:9092/sonar
# directory containing H2 database files.By default it's the /data directory in the SonarQube installation.
#sonar.embeddedDatabase.dataDir:
# H2 embedded database server listeningport, defaults to 9092
#sonar.embeddedDatabase.port: 9092
#----- MySQL 5.x
# Comment the embedded database anduncomment the following line to use MySQL
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
3) 启动sonar
运行D:\sonar-3.7.4\bin\windows-x86-64\InstallNTService.bat,运行后sonar将被安装成windows服务,我们可以到services.msc里开启sonar服务
4) 访问
浏览器打开http://localhost:9000访问sonar
6、 sonar-runner安装和配置
到http://www.sonarqube.org/downloads/下载sonar-runner,如:sonar-runner-dist-2.4.zip,
解压sonar-runner-dist-2.4.zip,到任意路径,如:D:\sonar-runner-2.4
1) 配置sonar-runner配置文件
修改D:\sonar-runner-2.4\conf\sonar-runner.properties,更改账号信息和数据源信息
#Configure here general information aboutthe environment, such as SonarQube DB details for example
#No information about specific projectshould appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- Security (when'sonar.forceAuthentication' is set to 'true')
sonar.login=admin
sonar.password=admin
2) 添加环境变量:
SONAR_RUNNER_HOME
D:\sonar-runner-2.4