十分钟搭建和使用sonarqube代码质量管理平台
前言
Sonarqube为静态代码检查工具,采用B/S架构,帮助检查代码缺陷,改善代码质量,提高开发速度,通过插件形式,可以支持Java、C、C++、JavaScripe等等二十几种编程语言的代码质量管理与检测。本文介绍如何快速安装、配置、使用Sonarqube及Sonarqube Scanner。
工作原理
Sonaqube-scanner:负责搜集代码相关数据 (可以理解为搜集端)
Sonarqube:负责对搜集的数据进行分析,通过不同的插件算法来对这些结果进行再加工,最终以量化的方式来衡量代码质量,最终展现给用户。

环境信息
| IP | 功能 | 软件 | 安装路径 | 操作系统 |
| 192.168.9.11 | sonarqube服务端 | jdk1.8.0_151,mysql5.7.21 sonarqube6.7 | /usr/local/ | centos7.5 |
| 192.168.9.12 | sonarqube-scanner客户端 | sonarqube-scanner3.2.0 | d:/sonar | windows7 |
搭建步骤:(sever端安装jdk mysql过程略)
sonarqube的安装
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.7.zi
unzip sonarqube-6.7.zip -d /usr/local/
useradd sonar
chown -R sonar. /usr/local/sonarqube-6.7/
sonarqube配置文件修改
vim /usr/local/sonarqube-6.7/conf/sonar.properties
sonar.web.host=0.0.0.0
sonar.web.port=9000
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.driver=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=password
建立数据库 (在数据库中建立需使用的库)
mysql -u root -p
> CREATE USER 'sonar’@'%' IDENTIFIED BY 'password';
> GRANT all privileges ON sonarqube.* TO sonar’@‘%' IDENTIFIED BY 'password';
> flush privileges;
> create database sonarqube;
启动及关闭
cd /usr/local/sonarqube-6.7/bin/linux-x86-64
./sonar.sh start
./sonar.sh stop
通过浏览器登录查看,并使用缺省密码登录。(可以在“配置”项的“应用市场”中选择安装中文插件来支持中文,)

sonarqube-scanner的安装
1.下载sonar-scanner-3.2.0.1227-windows.zip并解压,将bin文件加入环境变量path中如我的路径D:\sonar\sonar-scanner\bin将此路径加入path中
2.编辑配置文件conf/sonar-scanner.properties。根据数据库使用情况进行取消相关的注释即可,同时需要添加数据库用户名和密码信息,即配置要访问的sonar服务和mysql服务器地址
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here #----- Default SonarQube server
sonar.host.url=http://192.168.9.11:9000 #----- Default source code encoding
#sonar.sourceEncoding=UTF-
sonar.jdbc.username=sonar
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:mysql://192.168.9.150:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
3.编辑sonar-project.properties 放入需要扫描的project中(注意:同时要在sonarqube里添加对应的项目名称)
# must be unique in a given SonarQube instance
sonar.projectKey=saas_core
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=saas_core
sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=saas_core
sonar.binaries=bin
sonar.language=java
sonar.java.binaries=D:\sonar\saas_core
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-
4.sonar-scanner执行扫描分析
sonar-scanner -X
以上分析执行后,会将分析数据上传至sonarqube,在sonarqube中分析完成后,就可以看到分析结果

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
十分钟搭建和使用sonarqube代码质量管理平台的更多相关文章
- SonarQube代码质量管理平台比较好的搭建和使用资料
http://www.voidcn.com/blog/lidujun1028/article/p-3831235.html Sonar (SonarQube)是一个开源平台,用于管理源代码的质量. ...
- SonarQube代码质量管理平台介绍与搭建
前 言 1.SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质量(为什么要用SonarQube): (1) 复杂度分布(complexity):代码复 ...
- SonarQube代码质量管理平台工具
1.Sonar轮廓介绍 Sonar (SonarQube)是一个开源平台,用于管理源代码的质量.Sonar 不只是一个质量数据报告工具,更是代码质量管理平台.支持的语言包括:Java.PHP.C#.C ...
- SonarQube代码质量管理平台安装与使用
Sonar简介 Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检测代码质量 通过插件形式,可以支持包括java,C#,C/C++,PL/SQL,Cobol,JavaS ...
- SonarQube代码质量管理平台安装与使用--转载
原文:http://blog.csdn.net/hunterno4/article/details/11687269 Sonar简介 Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量, ...
- Dubbo入门到精通学习笔记(五):持续集成管理平台之sonarqube代码质量管理平台的介绍与安装
文章目录 SonarQube的介绍 SonarQube的安装 安装简介 详细安装过程 详细使用过程 SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质 ...
- 持续集成篇-- SonarQube代码质量管理平台的配置与使用
样例视频教程:http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53 一.SonarQube的配置(前提,先用admin用 ...
- Linux中 SonarQube代码质量管理平台以及C++插件安装
SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube安装 1.环境准备 (1)sonarQube 下载地址https://www.sonarqu ...
- Linux中 SonarQube代码质量管理平台安装
SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube安装 1.环境准备 (1)sonarQube 下载地址https://www.sonarqu ...
随机推荐
- yii2.0数据库查询修改等方法
yii2.0学习有一段时间了,给大家分享一下一些简单的查询等如何操作. 查询:(这里最前面的Test是引用的模型名) Test::find()->all(); 此方法返回所有数据: Tes ...
- GitHub & Git 基础 (YouTube中文翻译版)
GitHub & Git 基础系列视频 播放列表 由于视频资源在YouTube上,可能需要FQ:https://code.google.com/p/chromeplus/ 视频包括以下内容 1 ...
- tomcat 8 startup.bat启动乱码问题
修改Tomcat bin目录下startup.bat文件 将call "%EXECUTABLE%" start %CMD_LINE_ARGS% 改为 call "%EX ...
- 弃坑pexpect,入坑paramiko
上文书说到,ssh库pexpect的使用,简直就是个“月亮公主”——满眼全是坑.勉强把程序写好了,跑起来的时候发现了一个新坑,让我不可抗拒的把它弃掉了——经常莫名其妙的连不上服务器!开线程连接14台服 ...
- oracle 日期常用函數sysdate
SYSDATE 2 --◎ 可得到目前系統的時間 3 4 ex. 5 select sysdate from dual; 6 ...
- What Are Threads?
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/AboutThrea ...
- BZOJ2438:[中山市选2011]杀人游戏(强连通分量)
Description 一位冷血的杀手潜入 Na-wiat,并假装成平民.警察希望能在 N 个人里面,查出谁是杀手.警察能够对每一个人 进行查证,假如查证的对象是平民,他会告诉警察,他认识的人, 谁是 ...
- BZOJ2882:工艺(SAM)
Description 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工 ...
- luogu P3950 部落冲突
嘟嘟嘟 树剖板子题. #include<cstdio> #include<iostream> #include<algorithm> #include<cma ...
- js 页面 json对象转数组
json_array(data); function json_array(data){ var len=eval(data).length; var arr=[]; for(var i=0;i< ...