# Sonar 代码质量管理
Sonar 是一个用于代码质量管理的开放平台。通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具。
# Sonar 安装
官网地址 https://www.sonarqube.org/
从官网下载zip包并解压
# Sonar 配置
* 配置Sonar使用mysql数据库
创建 table sonar;
修改 conf/sonar.properties
'''
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
'''
* Sonar 启动
bin/linux-x86-64/sonar.sh start
# 安装的插件
* chinese Pack
* SonarJava
* SonarPython
* SonarJS
* Findbugs
# 代码检查
使用 sonar-scanner
下载 sonar-scanner-cli-3.0.3.778-linux.zip
配置 conf/sonar-scanner.propertie
'''
sonar.host.url=http://10.201.10.128:9000
sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.login=admin
sonar.password=admin
'''
在代码根目录
配置 sonar-project.properties
'''
# must be unique in a given SonarQube instance
sonar.projectKey=test:master
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=script-scanner
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=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.language=java
'''
sonar.projectKey 需要在 sonarqube 中创建唯一key
配置环境变量
vi /etc/profile
'''
export PATH=${PATH}:xxxxxx
'''
source /etc/profile
启动 sonar-scanner
访问 http://127.0.0.1:9000 查看项目检查情况
没研究明白iteye的md 后续补图
Sonar 代码质量管理
猜你喜欢
转载自endless2009.iteye.com/blog/2374690
今日推荐
周排行