前言

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. easyui学习笔记7—在手风琴中显示表格

    在这一篇中我们看看如何在手风琴里面显示表格数据的. 1.先看看引用的资源 <link rel="stylesheet" type="text/css" h ...

  2. [零基础学JAVA]Java SE面向对象部分.面向对象基础(02)

    String类 JAVA:public class StringTest{ public static void main(String args[]){ //尽量避免使用new,这样会产生内存垃圾 ...

  3. tp5中分页携带参数的方法

    $list = $model->where(...)->order(.....)->paginate($size, false, [                'query' = ...

  4. IOS ASI (第三方请求)

    什么是ASI全称是ASIHTTPRequest,外号“HTTP终结者”,功能十分强大基于底层的CFNetwork框架,运行效率很高可惜作者早已停止更新,有一些潜在的BUG无人去解决很多公司的旧项目里面 ...

  5. AngularJs学习笔记--Dependency Injection(DI,依赖注入)

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/di 一.Dependency Injection(依赖注入) 依赖注入(DI)是一个软件设计模式,处理 ...

  6. 在一个jsp页面中引用另一个jsp文件的路径的问题

    为了提高代码的重用性,经常需要在一个jsp页面中引用另一个jsp文件的代码.关于引用时的路径的问题.下面只介绍动态引用的,我觉得静态引用的应该也一样. 相对路径: 一.在同一个文件夹下,a.jsp中引 ...

  7. BZOJ2005:[NOI2010]能量采集(莫比乌斯反演,欧拉函数)

    Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得 ...

  8. 2019.1.1 在重写的方法上面添加@Override注解方法报错解决办法

    报错代码 The method transfer(Integer, Integer, Double) of type AccountServiceImpl must override a superc ...

  9. c#用链表来存储并读取写好的配置文件

    别用arraylist,效果没有list好(因为要装箱拆箱,所以会影响性能) 使用list,那我们就来先声明一个List 1) 声明 List<元素类型> myList = new Lis ...

  10. mac使用brew安装配置常见测试工具

    Homebrew 包管理工具可以让你安装和更新程序变得更方便,目前在 OS X 系统中最受欢迎的包管理工具是 Homebrew. 安装 在安装 Homebrew 之前,需要将 Xcode Comman ...