sonaqube 安装配置与sonar runner 配置
2015-03-30 17:49
429 查看
Sonar简介
Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检测代码质量
通过插件形式,可以支持包括java,C#,C/C++,PL/SQL,Cobol,JavaScrip,Groovy等等二十几种编程语言的代码质量管理与检测
一: SonarQube安装
预置条件
1.已安装JAVA环境
2.已安装有MySQL数据库
软件下载地址:http://www.sonarqube.org/downloads/
下载SonarQube与SonarQube Runner
中文补丁包下载:http://docs.codehaus.org/display/SONAR/Chinese+Pack
1.数据库配置
进入数据库命令
#mysql -u root -p
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;
2.安装sonar与sonar-runner
将下载的sonar-3.7.zip包解压至Linux某路径如/usr/local
将下载的sonar-runner-dist-2.3.zip包解压某路径/usr/local
添加SONAR_HOME、SONAR_RUNNER_HOME环境变量,并将SONAR_RUNNER_HOME加入PATH
个人配置参考:
SONAR_HOME :C:\soft\sonarqube-4.5.4
SONAR_RUNNER_HOME: C:\soft\sonar-runner-2.4
path 路径: %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;C:\soft\sonar-runner-2.4\bin
修改sonarqube配置文件
编辑<install_directory>/conf/sonar.properties文件,配置数据库设置,默认已经提供了各类数据库的支持
这里使用mysql,因此取消mysql模块的注释
#vi sonar.properties
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
# Optional properties
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
个人配置参考如下:
#----- MySQL 5.x
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar? useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
修改sonar-runner的配置文件
切换至sonar-runner的安装目录下,修改sonar-runner.properties
根据实际使用数据库情况取消相应注释
[java] view
plaincopy
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should 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
个人参考配置如下:
#----- 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
#----- 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
3.添加数据库驱动
除了Oracle数据库外,其它数据库驱动都默认已经提供了,且这些已添加的驱动是sonar唯一支持的,因此不需要修改
如果是Oracle数据库,需要复制JDBC驱动至<install_directory>/extensions/jdbc-driver/oracle目录
4.启动服务
目录切换至sonar的<install_directory>/bin/linux-x86-64/目录,启动服务
#./sonar.sh start 启动服务
#./sonar.sh stop 停止服务
#./sonar.sh restart 重启服务
至此,sonar就安装好了
访问http:\\localhost:9000即可
5.sonar中文补丁包安装
中文包安装
安装中文补丁包可以通过访问http:\\localhost:9000,打开sonar后,进入更新中心安装
或者下载中文补丁包后,放到SONARQUBE_HOME/extensions/plugins目录,然后重启SonarQube服务
二:使用SonarQube Runner分析源码
预置条件
已安装SonarQube Runner且环境变量已配置,即sonar-runner命令可在任意目录下执行
1.在项目源码的根目录下创建sonar-project.properties配置文件
以Java项目为例:
sonar.projectKey=beebank //项目名称
sonar.projectName=beebank //项目名称
sonar.projectVersion=1.0
sonar.sources=src
//sonar.binaries=bin\classes
sonar.language=java
sonar.sourceEncoding=UTF-8
3.执行分析
切换到项目源码根目录,执行命令
# sonar-runner
分析成功后访问http:\\localhost:9000即可查看分析结果
与IDE关联
最后,当然了,得与IDE相关联,才能更方便地实时查看
以Eclipse为例,请见:http://docs.sonarqube.org/display/SONAR/SonarQube+in+Eclipse
附:
sonarQube官网地址:http://www.sonarqube.org/
sonarQube官方文档地址:http://docs.codehaus.org/display/SONAR/Documentation
sonarQube示例地址:http://nemo.sonarqube.org/
网上另两篇相关的文章:http://www.cnblogs.com/gao241/p/3190701.html
http://www.myexception.cn/open-source/1307345.html
Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检测代码质量
通过插件形式,可以支持包括java,C#,C/C++,PL/SQL,Cobol,JavaScrip,Groovy等等二十几种编程语言的代码质量管理与检测
一: SonarQube安装
预置条件
1.已安装JAVA环境
2.已安装有MySQL数据库
软件下载地址:http://www.sonarqube.org/downloads/
下载SonarQube与SonarQube Runner
中文补丁包下载:http://docs.codehaus.org/display/SONAR/Chinese+Pack
1.数据库配置
进入数据库命令
#mysql -u root -p
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;
2.安装sonar与sonar-runner
将下载的sonar-3.7.zip包解压至Linux某路径如/usr/local
将下载的sonar-runner-dist-2.3.zip包解压某路径/usr/local
添加SONAR_HOME、SONAR_RUNNER_HOME环境变量,并将SONAR_RUNNER_HOME加入PATH
个人配置参考:
SONAR_HOME :C:\soft\sonarqube-4.5.4
SONAR_RUNNER_HOME: C:\soft\sonar-runner-2.4
path 路径: %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;C:\soft\sonar-runner-2.4\bin
修改sonarqube配置文件
编辑<install_directory>/conf/sonar.properties文件,配置数据库设置,默认已经提供了各类数据库的支持
这里使用mysql,因此取消mysql模块的注释
#vi sonar.properties
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
# Optional properties
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
个人配置参考如下:
#----- MySQL 5.x
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar? useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
修改sonar-runner的配置文件
切换至sonar-runner的安装目录下,修改sonar-runner.properties
根据实际使用数据库情况取消相应注释
[java] view
plaincopy
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should 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
个人参考配置如下:
#----- 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
#----- 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
3.添加数据库驱动
除了Oracle数据库外,其它数据库驱动都默认已经提供了,且这些已添加的驱动是sonar唯一支持的,因此不需要修改
如果是Oracle数据库,需要复制JDBC驱动至<install_directory>/extensions/jdbc-driver/oracle目录
4.启动服务
目录切换至sonar的<install_directory>/bin/linux-x86-64/目录,启动服务
#./sonar.sh start 启动服务
#./sonar.sh stop 停止服务
#./sonar.sh restart 重启服务
至此,sonar就安装好了
访问http:\\localhost:9000即可
5.sonar中文补丁包安装
中文包安装
安装中文补丁包可以通过访问http:\\localhost:9000,打开sonar后,进入更新中心安装
或者下载中文补丁包后,放到SONARQUBE_HOME/extensions/plugins目录,然后重启SonarQube服务
二:使用SonarQube Runner分析源码
预置条件
已安装SonarQube Runner且环境变量已配置,即sonar-runner命令可在任意目录下执行
1.在项目源码的根目录下创建sonar-project.properties配置文件
以Java项目为例:
sonar.projectKey=beebank //项目名称
sonar.projectName=beebank //项目名称
sonar.projectVersion=1.0
sonar.sources=src
//sonar.binaries=bin\classes
sonar.language=java
sonar.sourceEncoding=UTF-8
3.执行分析
切换到项目源码根目录,执行命令
# sonar-runner
分析成功后访问http:\\localhost:9000即可查看分析结果
与IDE关联
最后,当然了,得与IDE相关联,才能更方便地实时查看
以Eclipse为例,请见:http://docs.sonarqube.org/display/SONAR/SonarQube+in+Eclipse
附:
sonarQube官网地址:http://www.sonarqube.org/
sonarQube官方文档地址:http://docs.codehaus.org/display/SONAR/Documentation
sonarQube示例地址:http://nemo.sonarqube.org/
网上另两篇相关的文章:http://www.cnblogs.com/gao241/p/3190701.html
http://www.myexception.cn/open-source/1307345.html
相关文章推荐
- 2017.4.18 静态代码分析工具sonarqube+sonar-runner的安装配置及使用
- 2017.4.18 静态代码分析工具sonarqube+sonar-runner的安装配置及使用
- 开发人员学Linux(10):CentOS7安装配置代码质量管理平台SonarQube
- SonarQube的安装、配置与使用
- sonarQube的配置和使用(在本地安装)
- SonarQube的安装、配置与使用
- SonarQube之——SonarQube 代码质量管理平台的安装与配置
- Linux环境安装SonarQube,windows使用SonarQube Runner完整实例
- 开发人员学Linux(10):CentOS7安装配置代码质量管理平台SonarQube6.4
- SonarQube的安装、配置与使用
- SonarQube安装、配置、扫描代码
- SonarQube安装配置
- SonarQube 安装及配置
- SonarQube的安装、配置与使用
- 分布式架构学习之持续集成:011--SonarQube代码质量管理平台的安装、配置和使用
- SonarQube 安装配置使用
- SonarQube的安装、配置与使用
- linux安装sonarQube的安装、配置与使用
- SonarQube安装与配置
- 代码质量管理平台SonarQube的安装、配置与使用