前言

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代码质量管理平台的更多相关文章

  1. SonarQube代码质量管理平台比较好的搭建和使用资料

    http://www.voidcn.com/blog/lidujun1028/article/p-3831235.html   Sonar (SonarQube)是一个开源平台,用于管理源代码的质量. ...

  2. SonarQube代码质量管理平台介绍与搭建

    前 言 1.SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质量(为什么要用SonarQube): (1) 复杂度分布(complexity):代码复 ...

  3. SonarQube代码质量管理平台工具

    1.Sonar轮廓介绍 Sonar (SonarQube)是一个开源平台,用于管理源代码的质量.Sonar 不只是一个质量数据报告工具,更是代码质量管理平台.支持的语言包括:Java.PHP.C#.C ...

  4. SonarQube代码质量管理平台安装与使用

    Sonar简介 Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检测代码质量 通过插件形式,可以支持包括java,C#,C/C++,PL/SQL,Cobol,JavaS ...

  5. SonarQube代码质量管理平台安装与使用--转载

    原文:http://blog.csdn.net/hunterno4/article/details/11687269 Sonar简介 Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量, ...

  6. Dubbo入门到精通学习笔记(五):持续集成管理平台之sonarqube代码质量管理平台的介绍与安装

    文章目录 SonarQube的介绍 SonarQube的安装 安装简介 详细安装过程 详细使用过程 SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质 ...

  7. 持续集成篇-- SonarQube代码质量管理平台的配置与使用

    样例视频教程:http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53 一.SonarQube的配置(前提,先用admin用 ...

  8. Linux中 SonarQube代码质量管理平台以及C++插件安装

    SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube安装 1.环境准备 (1)sonarQube 下载地址https://www.sonarqu ...

  9. Linux中 SonarQube代码质量管理平台安装

    SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube安装 1.环境准备 (1)sonarQube 下载地址https://www.sonarqu ...

随机推荐

  1. 索引反向使用案例,加index_desc hint

    drop index idx_t;create index idx_t on t(owner desc,object_type asc); select /*+index(a,idx_t)*/ * f ...

  2. (原)使用 memcache 使用过程中可能遇到的问题

    在项目优化中,使用到了memcache,刚开始不能用,后来期间总会偶尔抛出异常,刚开始怀疑动态库版本问题,后来尝试了各种替换依旧误解,搞得我日思夜想的,天天惦记着他..=_= 下午拿出半天时间,进行错 ...

  3. 一直在用的一个javascript网站

    http://www.dottoro.com/ 很不错,例子丰富,解释详细,全面:非常好的参考资料站.

  4. Android webview 点击超链接打开新的webview

    webview.setWebViewClient(new webViewClient() { HitTestResult hit = view.getHitTestResult(); if (hit ...

  5. 设置 jsp 表格相邻两行的颜色不一样

    转载网址:https://zhidao.baidu.com/question/134905332.html?fr=iks&word=for+%28var+i%3D0%3Bi%3CTable.r ...

  6. 【[JLOI2013]卡牌游戏】

    思路太妙了 刚开始yy出了一种比较自然的dp方法,就是按照游戏的进行来开始dp,设\(dp[i][j]\)表示第\(i\)个人为庄家,还剩下\(j\)个人的概率为多少,但是很快发现这个样子没法转移,因 ...

  7. MS12-020蓝屏攻击

    MS12-020远程桌面协议RDP拒绝访问漏洞 条件:受害者必须开放RDP协议 开放了3389端口 或者端口改了,知道对方RDP开放的对应端口. 过程:MSF利用 MSF显示为seems down说明 ...

  8. 【luogu P1073 最优贸易】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1073 对于状态量相互影响的题目,分层图是个不错的想法. 考虑在题目中分为: 不交易: 直接从1到n出去,为0 ...

  9. OC变量命名禁忌

    OC变量命名禁忌 1.在NSString类不能定义变量名为description, 每个类都有 - (NSString *)description{} 这样一个get方法. 2.不能将变量的名称定义为 ...

  10. 【Node.js】新建一个NodeJS 4.X项目

    前提工作 1.安装Node.js 各种下一步就好 2.安装NPM(node package manager) 安装好Node.js之后,打开cmd,输入npm install npm -g,程序会自动 ...