1.sonarqube下载地址
https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip
2.sonarqube配置
Sonar配置,conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=123456
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.port=9000
3.新建数据库sonar
4.服务启动
Sonar服务启动,bin/目录下依次运行
InstallNTService.bat
StartNTService.bat
StartSonar.bat
4.1 bug wrapper | OpenSCManager failed - 拒绝访问。 (0x5)
使用管理员身份运行
4.2 bug 启动自动停止
有可能是mysql版本过低
#----- 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.
5服务访问
Sonar Web访问
浏览器打开http://localhost:9000,默认管理员用户密码 admin admin。
6.Sonar Scanner扫描下载
7. 将 <install_directory> / bin 目录添加到环境变量path中
8. sonar-scanner
usage: sonar-scanner [options]
Options:
-D,--define <arg> Define property
-h,--help Display help information
-v,--version Display version information
-X,--debug Produce execution debug output
如果需要更多调试信息,可以sonar.verbose 通过添加命令行参数来添加 属性 -Dsonar.verbose=true。使用
9在项目的根目录中创建配置文件:sonar -project.properties
sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=My project
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=My project
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
sonar.java.binaries=./target/classes
从项目基目录运行以下命令以启动分析:sonar-scanner
10安全
任何被授予执行分析 权限的用户都 可以运行分析。
如果 任何人 组未被授予 执行分析 权限,或者SonarQube实例受到保护(该 sonar.forceAuthentication 属性设置为 true),则 必须通过该 属性提供具有执行分析权限 的用户的分析令牌 sonar.login。示例: sonar-scanner -Dsonar.login=[my analysis token]
11 bug sonar-scanner扫描代码出错 SonarQube svn: E175002
分析原因应该是sonar扫描的代码中有中文字符导致,打开sonarqube的控制台,使用admin登录后 ,在配置->SCM->菜单中,将Disabled the SCM Sensor设置为true
12 bug 故障排除Java堆空间错误或java.lang.OutOfMemoryError,
通过SONAR_SCANNER_OPTS环境变量增加内存:
export SONAR_SCANNER_OPTS="-Xmx512m"
在Windows环境中,请避免使用双引号,因为它们会被误解并将这两个参数合并为一个参数。
set SONAR_SCANNER_OPTS=-Xmx512m