windows11安装使用sonarqube7.8
环境说明
sonarqube7.9及以上不再支持MySQL,不支持jdk1.8。 工具下载地址:https://binaries.sonarsource.com/?prefix=Distribution/
操作系统:windows 11 安装软件:jdk1.8,maven 3.6,SonarQube7.8,mysql5.7
安装sonarqube
提前配置好jdk、mysql和maven。 在上面的工具下载地址中找到sonarqube
下载:https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.8.zip 解压下载的安装包。 双击StartSonar.bat 在浏览器中访问http://localhost:9000/,默认账号和密码都是admin。
配置sonarqube
创建数据库,默认编码utf8 MySQL数据库必须是InnoDB存储引擎,不支持MyISAM 通过可视化工具连接MySQL,创建数据库sonar。或通过命令窗口连接。
#命令行 窗口:mysql -u root -p //登录数据库 create database sonar default character set utf8 collate utf8_general_ci;
修改sonar.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.jdbc.username=root sonar.jdbc.password=123456 sonar.sorceEncoding=UTF-8 sonar.login=admin sonar.password=admin
关闭sonarqube,重启sonarqube。 就能看到数据库表已经初始化完成。 再次访问http://localhost:9000/。 SonarQube Scanner 是默认Scanner,Sonar为Maven、Gradle等都开发了Scanner。如果项目没有使用Maven、Gradle,请使用默认的Scanner。
安装SonarQube Scanner
下载地址:https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-windows.zip。 解压以后,修改sonar-scanner.properties。
#----- Default SonarQube server sonar.host.url=http://localhost:9000 #----- Default source code encoding sonar.sourceEncoding=UTF-8
配置环境变量
# 在DOS窗口中输入一下命令 sonar-scanner -h # 出现以下信息,则表示环境变量设置成功
使用
进入待检测项目的根目录中,新建sonar-project.properties文件,文件内容为:
# must be unique in a given SonarQube instance sonar.projectKey=ner_predict_model # 修改为自己的 # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=ner_predict_model # 修改为自己的 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=. # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8
打开DOS窗口,切换目录到项目目录,输入sonar-scanner 运行成功后,打开web界面,即可看到对当前项目的分析。 至此扫描完成,如果需要导出PDF文件,需要安装一个插件。
插件下载地址:https://gitee.com/zzulj/sonar-pdf-plugin/releases 下载jar文件,放到 关闭sonarqube,重启sonarqube。
点击download下载即可。
常见问题
1、出现 {“error”:“Report is not available. At least one analysis is required after installing the plugin!”}
解决方法: 安装了导出插件后,记得配置用户名和密码,然后重新扫描项目。