SonarQube代码质量管理平台的配置与使用

一.下载

SonarQube:

https://www.sonarqube.org/downloads/

sonar-scanner:

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

本地管理界面:

http://localhost:9000/

二.配置sonarqube

1.打开mysql,新建一个数据库。

2.编辑sonarqube目录下的\conf\sonar.properties文件

#----- MySQL 5.6 or greater
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
sonar.jdbc.url=jdbc:mysql://192.168.1.138:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=username
sonar.jdbc.password=password
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin

3.启动sonarqube,启动有可能会几分钟

数据库会自动导入

4安装中文语言包

首先需要登录

重启之后变为中文管理界面

三.配置sonar-scanner-cli

1配置环境变量SONAR_SCANNER_HOME并加入path

a.新建变量,

name=SONAR_RUNNER_HOME。

value=D:\jobInfo\sonar-scanner-cli-3.2.0.1227-windows\sonar-scanner-3.2.0.1227-windows

b.path添加%SONAR_RUNNER_HOME%\bin;

2命令行验证

3编辑sonar-scanner目录下的\conf\sonar-scanner.properties文件

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
sonar.jdbc.url=jdbc:mysql://192.168.1.138:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=username
sonar.jdbc.password=password
#----- Default source code encoding
sonar.sourceEncoding=UTF-8

 

四.配置项目

打开要进行代码分析的项目根目录,新建sonar-project.properties文件,注意路径斜杠写法

# must be unique in a given SonarQube instance
sonar.projectKey=projectName
# this is the name displayed in the SonarQube UI
sonar.projectName=projectName
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=D:/Users/Java/git/projectName
 
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
sonar.java.binaries=D:/Users/Java/git/sleepdetector/target/classes

 

五.运行

在命令行中进入到项目所在根目录执行sonar-scanner

 

六.界面管理

出现了刚才执行检查的项目的信息,可以根据质量提示进行代码的优化管理

猜你喜欢

转载自blog.csdn.net/lin252552/article/details/86082266