SonarQube是一款代码质量检测工具,用于检测代码BUG,漏洞之类的,当然这类工具是辅助工具,不一定是代码有问题,需要设置扫描规则

如果需要使用轻量级的,则可以直接安装sonarlint IDEA插件,本地化操作,不需要安装SonarQube服务端
sonarlint 连接SonarQube

环境检查:

首选需要用到数据库,oracle、sql server、mysql都可以
这里使用mysql,安装之前需要先检查环境配置,
SonarQube8.0以上使用的是JDK11以上版本,本地环境是JDK8,因此下载的是SonarQube7.4,但是要求mysql版本[5.6-8),因此装机mysql是5.7版本


安装:

1.安装数据库

安装数据库,此处选用mysql5.7
–mysql-zip版本安装
–建用户赋权


2.配置启动SonarQube

根目录conf/sonar.properties,添加数据库连接配置

#----- DEPRECATED
#----- MySQL >=5.6 && <8.0
# Support of MySQL is dropped in Data Center Editions and deprecated in all other editions
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=falsesonar.jdbc.url=jdbc:mysql://localhost:3307/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=sonarqube
sonar.jdbc.password=sonarqube
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin

上面的信息明确显示mysql版本5.6-8.0

以管理员运行cmd,sonarqube-7.4\bin\windows-x86-64,执行StartSonar.bat

之间会初始化数据库,建立60张表

3.配置sonar-scanner

sonar-scanner-4.2.0.1873-windows\conf\sonar-scanner.properties
添加SonarQube访问地址

sonar.host.url=http://localhost:9000

配置环境变量path

D:\Program Files\sonar-scanner-4.2.0.1873-windows\bin

配置成功检测,执行命令 sonar-scanner --version

4.编写扫描文件

扫描文件位置需要放在项目根目录(与pom、src、target同级),统一命名为sonar-project.properties

# must be unique in a given SonarQube instance
sonar.projectKey=zyb-crm-service:project
# this is the name displayed in the SonarQube UI
sonar.projectName=cic-crm-service
sonar.projectVersion=1.0# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=src
sonar.java.binaries=target
#sonar.language=java
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

sonar.projectName:扫描项目名称
sonar.projectKey:自定义唯一项目key
sonar.sources:扫描目录(路径)
sonar.java.binaries:编译文件目录

5.扫描
cmd进入扫描项目根目录,执行命令sonar-scanner

6.与IDEA关联-插件
file–settings–plugins–sonar


可以选择sonarqube,不过轻量级使用sonarlint足够

问题:
1.上传文件大小限制:
sonar-scanner报错

ERROR: Error during SonarQube Scanner execution
ERROR: Failed to upload report - An error has occurred. Please contact your administrator

查看sonar安装目录下的logs中的web.log,里面有如下报错信息

Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (18307204 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3681)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2512)

是说向MySQL数据库中写数据的时候超过了单次最大数据量,可通过修改MySQL中max_allowed_packet参数进行解决。

在mysql配置文件中添加如下配置

2.重启SonarQube报错,关闭的链接

报错WrapperSimpleApp: Encountered an error running main: java.nio.file.FileSystemException: D:\sonarqube-7.8\temp\ce-exploded-plugins\authgithub\META-INF\lib\gson-2.3.1.jar: 另一个程序正在使用此文件,进程无法访问。

进入SonarQube安装目录,删除temp下所有内容

3.中文插件只有匹配SonarQube8.0问题
自己登陆下载相应版本的中文插件jar,下有链接,复制到SonarQube安装目录extensions\plugins下

下载:https://www.sonarqube.org/downloads/
中文插件:https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-1.24

SonarQube-代码质量检测工具相关推荐

  1. Docker搭建SonarQube代码质量检测工具

    SonarQube简介 SonarQube 是一款用于代码质量管理的开源工具,它主要用于管理源代码的质量. 通过插件形式,可以支持众多计算机语言,比如 java, C#, go,C/C++, PL/S ...

  2. 【IDEA】代码质量检测工具 QAPLug

    [IDEA]代码质量检测工具 QAPLug 代码质量检测工具 情景: 写完代码一定要别人review才发现bug或不好的语法或多余的变量是一件多么尴尬的事情,如果想在写代码时或者写代码后自己能发现问题 ...

  3. python代码检测工具及区别_flake8-python代码质量检测工具

    flake8是python代码质量检测工具. 描述 flake8是一个命令行实用程序,用于在整个Python项目中加强样式的一致性. 默认情况下,它包括PyFlakes项目提供的lint检查,PyCo ...

  4. 基于SonarQube代码质量检测

    基于SonarQube代码质量管理 SonarQube是什么? 官网:https://www.sonarqube.org/ Sonar (SonarQube)是一个开源平台,用于管理源代码的质量. S ...

  5. Docker运行sonarqube (代码质量检测平台)

    onarqube是什么 SonarQube是用于持续检查代码质量的开源平台. 可用于持续集成,持续部署流程中的代码检测环节. idea和jenkins都提供了插件配合使用. liunx推荐配置环境 l ...

  6. 淘宝开源的代码质量检测工具,真强啊~

    来源:github.com/ice-lab/iceworks/tree/master/ 好的代码一定是整洁的,并且能够帮助阅读的人快速理解和定位.好的代码可以加快应用的开发迭代速度,不必花过多的时间来 ...

  7. 淘宝开源代码质量检测工具!

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 好的代码一定是整洁的,并且能够帮助阅读的人快速理解和定位. ...

  8. 淘宝开源的代码质量检测工具!

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源:github.com/ice-lab/icewor ...

  9. 代码质量检测-SonarQube

    文章目录 前言 一.SonarQube是什么? 二.SonarQube安装步骤 1.docker安装 2.docker-compose安装 3. 访问SonarQube 4. 配置SonarQube ...

最新文章

  1. 跨平台PHP调试器设计及使用方法——界面设计和实现
  2. Oracle linux R5-U7中YUM 源配置
  3. python数组切片教程_手把手numpy教程【二】——数组与切片
  4. nodejs和Vue和Idea
  5. Linux命令【五】系统函数
  6. [vue] 删除数组用delete和Vue.delete有什么区别?
  7. python 分类变量回归_极简Python带你探索分类与回归的奥秘
  8. 从 0 到 300,Instagram 创始人 CTO 分享工程团队成长的经验
  9. Java Calendar toString()方法与示例
  10. SaaS市场没有免费午餐!未来只有两种企业可生存
  11. 大厂,君子好逑?大厂面试题你能过吗
  12. Android系统信息获取 之三:IMSI号和IMEI解释
  13. 清除每隔5000毫秒请求一次接口的定时器(需求:每当我手动核销电子码,页面上的显示数据要实时更新到)...
  14. 编译原理(王生源第三版)第一章学习笔记(含第一章习题)
  15. matlab 传函将s换为jw,已知单位负反馈系统开环传递函数为20 s(0.5s 1),
  16. 适用于Android的最佳本地音乐播放器
  17. BT4中文版(集成spoonwep2/spoonwpa) 破解无线网卡非常容易
  18. JWplayer入门及使用
  19. php手机验证码开发,php网站、手机验证码开发(手机注册验证)
  20. 容齐的身世_白发王妃漫夭和容齐是什么关系 女主容乐跟谁睡过遭扒可怜容齐...

热门文章

  1. Webex Player 安装文件,解决了不能播放问题,win7也能使用
  2. 从角雷达到前向雷达,中国厂商如何加速突围?
  3. linux 查看删除进程 ps命令详解
  4. Portraiture 3 for Mac使用教程
  5. 辣鸡百度云PC端密码输入老是错误的解决办法(即使你输入的是对的)
  6. 苏州企业认定为高新技术企业后就可以享受所得税优惠吗
  7. 目标检测中NMS和mAP指标中的的IoU阈值和置信度阈值
  8. 信号频率(Frequency),幅值(Amplitude),周期(Period),相位(Phase)所代表的含义与关系
  9. Android8.0以上系统ROOT时,Magisk框架替代SpuerSU
  10. PHP最常用的几种设计模式