一.SonarQube简介

SonarQube是一个开源的代码质量管理系统,可用来快速定位代码中的Bug、漏洞以及不优雅的代码。它支持几乎所有的常见编程语言,例如Java、JavaScript、TypeScript、Kotlin、Ruby、Go, Scala等。并且还有插件机制,利用插件,可以让SonarQube更加强大,例如可以整合Findbugs、PMD、Checkstyle等。可以说,SonarQube是一款提升项目代码质量必备的工具。

二.下载

前往 https://www.sonarqube.org/downloads/ ,按照如图说明下载即可。建议下载 LTS 版本,以便获得长期的维护与支持。

JDK(对于7.9.x,那么需要JDK 11或更高版;对于6.x - 7.8.x,需要JDK 8或更高版本)

注:本演示教程使用的版本:SonarQube 7.2.1 ,MySQL 5.7

三.安装与启动

  • 解压缩
  • 将目录切换到SonarQube的 /bin 目录,可看到类似如下的目录结构:
  • 根据自己的系统选择文件夹,这里演示的是在Windows下操作,选择 windows-x86-64文件夹
  • 执行 StartSonar.bat
  • 稍等片刻,访问 http://localhost:9000/,看到一下界面,说明安装成功!

  • 管理员登录(http://localhost:9000/sessions/new,默认账号:admin/admin)
  • Windows下sonarQube 重启比较奇葩:1.首先关闭SonarQube.bat窗口。2.调出资源管理器。3.在进程中关闭所有java.exe进程(不关闭java.exe会提示连接被占用)。4.重新点击StartSonar.bat。

四.配置数据库

默认情况下,SonarQube使用的是H2数据库,这是一款非常流行的嵌入式数据库。但生产环境中,SonarQube并不建议使用H2。SonarQube支持多种数据库,例如Qracle、PostgreSQL、SQL Server等。下面,我们以PostgreSQL为例,让SonarQube使用PostgreSQL存储数据。

SonarQube 7.9 开始正式不支持MySQL
SonarQube 7.9要求使用PostgreSQL 9.3-9.6或者PostgreSQL 10,并且必须配置使用UTF-8

根据 SonarQube 的版本确定MySQL 的版本,不能太高也不能太低,在安装路径下查看 conf/sonar.properties 文件

增加MySQL的连接配置

在安装路径下查看 conf/sonar.properties 文件,增加配置

sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false

在MySQL数据库中创建 sonar 数据库,重启服务,可以发现 sonarQube会自动往数据库里面新增表。

修改数据库为MySQL的踩坑记录

启动窗口提示以下信息:

################################################################################Database must be upgraded. Please backup database and browse /setup
################################################################################

打开:127.0.0.1:9000访问SonarQube,页面提示:

SonarQube is under maintenance. Please check back later.
Whilst waiting, you might want to check new plugins to extend the current functionality.
If you are an administrator and have no idea why this message is showing, you should read the upgrade guide


解决方法:需要重新进行初始化服务,访问地址为 http://localhost:9002/setup(更新数据库)

点击Upgrade按钮,并重启SonarQube服务,即可确认升级后的信息了. 这时候可能在启动窗口报错,更新数据库失败(没有报错更好)

org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #2128 'Purge duplicate rules_parameters and their orphans' failedat org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)at java.util.Iterator.forEachRemaining(Iterator.java:116)at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590)at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:50)at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: You can't specify target table 'p1' for update in FROM clauseat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)at org.sonar.server.platform.db.migration.step.UpsertImpl.execute(UpsertImpl.java:66)at org.sonar.server.platform.db.migration.version.v72.PurgeDuplicateRulesParameters.execute(PurgeDuplicateRulesParameters.java:64)at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:44)at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)... 11 common frames omitted

这个问题是数据迁移失败,其中有一块数据有问题。
解决方案:在数据库中手动插入不起作用的迁移

insert into schema_migrations values (2128);

重启一下sonar访问一下 http://localhost:9000/sonar

五.整合 maven

1.全局整合

在maven的 setting.xml中增加配置

<profile><id>sonar</id><activation><activeByDefault>true</activeByDefault></activation><properties><sonar.jdbc.url>数据库url</sonar.jdbc.url><sonar.jdbc.driver>数据库驱动包</sonar.jdbc.driver><sonar.jdbc.username>账号</sonar.jdbc.username><sonar.jdbc.password>密码</sonar.jdbc.password><sonar.host.url>sonarQube 地址</sonar.host.url></properties>
</profile>

到Maven项目的根目录执行如下命令,即可使用SonarQube分析项目,等待项目构建成功:

mvn sonar:sonar -Dsonar.java.binaries=target/sonar

访问 http://localhost/9000 可以看到

2.直接命令行控制

生成token


使用token

使用生成的 token,在项目代码的目录下执行 mvn 命令即可

六.汉化

使用自带的插件市场汉化

点击 Install 按钮后,将会弹出重启SonarQube的提示,点击即可重启。重启后,可看到类似如下的界面

类似的方式,也可为SonarQube安装其他插件。

踩坑

在插件市场中,可能版本和自己 sonarQube 的版本不匹配,导致插件无法安装,这时候需要自己下载汉化包进行汉化。
各版本对应的汉化包下载地址:https://github.com/xuhuisheng/sonar-l10n-zh/releases?page=3

将下载后的jar放入安装目录下 extensions\plugins 中,重启服务即可。

参考文章:http://www.imooc.com/article/291857

Windows 下载安装 SonarQube和使用相关推荐

  1. windows下载安装opencv

    windows下载安装opencv 文章目录 windows下载安装opencv 下载 安装 配置 测试 下载 可以在官网进行下载opencv但是下载的比较慢 官网:Home - OpenCV 点击l ...

  2. 原版windows下载安装方法

    原版windows下载安装方法: 1.下载windows原版镜像http://www.itellyou.cn/ 2.下载U盘启动盘制作工具http://www.microsoft.com/zh- cn ...

  3. Windows下载安装MySQL及相关配置教程

    Windows下载安装MySQL及相关配置教程 下载过程: 1.首先登陆官方网站进行下载:[https://dev.mysql.com/downloads/mysql/] 2.如图所示:step1:选 ...

  4. Windows下载安装Cytoscape3.8.2

    1 下载网址:https://cytoscape.org/download.html (windows已经安装了Java8) 2 直接安装Cytoscape会报错,去网址https://adoptop ...

  5. mac和windows下载安装redis

    1. windows下载和安装 官网地址: https://github.com/microsoftarchive/redis/releases 我的资源地址: https://download.cs ...

  6. windows 下载安装ES

    1.下载安装ES (1)从官网下载elasticsearch 地址:https://www.elastic.co/downloads/elasticsearch (2)解压zip到文件目录 (3)开启 ...

  7. windows下载安装小米的sql分析工具soar

    1.下载安装go 下载地址:https://studygolang.com/dl 安装完成,cmd窗口 go version C:\Users\ht251>go version go versi ...

  8. windows下载安装Vue开发者工具(VueDevtools),同时支持vue2.0和vue3.0两个版本

    前言 vue开发者工具可以帮助我们提高开发效率,如果不安装控制台老是现在这些东西,对我这种强迫症患者来说痛苦至极,下面我就介绍下我的安装步骤 下载安装 首先进入vue官网找到如下位置 然后就会进入gi ...

  9. Nginx在Windows下载安装启动与配置前后端请求代理

    场景 Nginx入门教程-简介.安装.反向代理.负载均衡.动静分离使用实例: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103 ...

  10. FFmpeg windows下载安装

    FFmpeg官网 FFmpeg官网地址:http://ffmpeg.org/ FFmpeg github地址:https://github.com/FFmpeg/FFmpeg 下载 windows下要 ...

最新文章

  1. 汉字转拼音缩写的函数以及其他函数
  2. 光纤接口怎么接 图解_光纤的数据比网线快很多倍,但为什么没有在家庭局域网中普及呢?...
  3. 通过CMD命令行创建和使用Android 模拟器 AVD
  4. 环境变量简单介绍windows-linux-mac
  5. Python实现计数排序
  6. C/C++排序算法(2)希尔排序
  7. python提取全部个股数据_Python 股票历史数据的获取
  8. 科学计算机怎样开根号,电脑上的科学计算器怎么开根号(科学计算器开4次方根操作方法)...
  9. 摄像头与成像——做图像处理必须了解的数字成像系统原理
  10. 阿里巴巴android开发规范,阿里巴巴开发手册|阿里巴巴Android开发手册 PDF电子版_最火软件站...
  11. 一篇很哇塞的MyBatis入门到精通
  12. 交互式电子白板android,交互式电子白板教学应用
  13. 安卓应用改变logo图标和名称
  14. 如何将PDF压缩突破限制大小
  15. SpringBoot整合Elastricsearch + LogStash + Kibana太简单了!
  16. 百度智能产品初现“卡组效应”:矩阵优势究竟对硬件市场有多重要
  17. 如何安全的清除linux访问记录
  18. 海洋cms泛目录系统
  19. Windows x64内核学习笔记(二)—— IA-32e模式
  20. 设计模式之禅--读后感

热门文章

  1. 医院职工离职申请证明模板,共计10篇
  2. java贪吃蛇难度设计_Java贪吃蛇应用的设计与实现
  3. 串口监视软件_力控监控组态软件与西门子S7200
  4. 春运买不到票?程序员喊你来GitHub看牛哄哄的抢票神器
  5. 黑莓开发之经典九宫格设计
  6. 计算机网络布线总结,网络综合布线实训总结
  7. 软件那么多,恢复数据还靠它
  8. 百度文档ppt,word文档下载
  9. Python玩转emoji表情 一行代码的事儿!
  10. Genius‘s Gambit【学习进度条1】