Sonar基础配置及使用
首先说下我的使用版本:
SonarQube 6.4 下载地址:https://www.sonarqube.org/downloads/
sonar-scanner2.5.1下载地址:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.1.zip
中文插件包sonar-l10n-zh-plugin-1.16.jar:https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases
我是使用环境:windows 64bit 本地使用
1、开始使用:
解压SonarQube6.4,sonar-scanner2.5.1
插件包使用方法:直接拷贝到sonarqube下的extensions\plugins包下。
2、修改SonarQube6.4/conf/sonar.properties
主要配置了用户名/密码和数据库等的相关信息
sonar.login=admin
sonar.password=admin
sonar.jdbc.username=user
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.port=9090#修改了下端口,默认的好像9000,我的居然冲突了,可能是开的程序太多,就直接换了一个
3、启动
双击bin\windows-x86-64\StartSonar.bat
在浏览器中打开http://localhost:9090就可以打开sonarqube窗口,如果配置了数据库打开可能会有点慢,稍等一会儿就行
4、添加项目
打开sonar-scanner-2.5.1\conf\sonar-runner.properties文件
配置mysql信息
sonar.jdbc.username=user
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
如果端口改了,就设置sonar.host.url=http://localhost:9090
5、配置环境变量
name:SONAR_RUNNER_HOME,value:E:\test\sonar-scanner-2.5.1
打开path,输入%SONAR_RUNNER_HOME%\bin,打开新的cmd窗口,输入sonar-runner -version显示版本表示设置成功
6、新建sonar-project.properties
# must be unique in a given SonarQube instance sonar.projectKey=my:project # this is the name displayed in the SonarQube UI sonar.projectName=apiautocore 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=src # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8
projectName是项目名字,sources是源文件所在的目录
7、设置成功后,启动sonarqube服务,并启动cmd
8、在cmd进入项目所在的根目录,输入命令:sonar-runner,分析成功。。。
9、打开http://localhost:9090/ 就可以看到代码分析结果。
以上是亲自手动实验成功的
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器