Sonar配置,严格按步骤做下来,一定可以的

环境前提:安装java(JAVA_HOME, PATH), 我使用jdk8(64位)。系统为win7(64) 。实验需要验证的项目为一般java web项目(我命名之TEST项目),直接通过.classpath组织lib,未使用maven/git等手段。
1、下载SonarQube:sonarqube-4.5.7 (http://www.sonarqube.org/downloads/ 点击 Show all versions ),解压。
2、建立mysql库:(我用的版本:5.5, 各位照抄)
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;
3、修改sonarqube的配置:\sonarqube-4.5.7\conf\sonar.properties(如果第2步照抄了,就这三行,其他的不要动)
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
4、启动SonarQube, \sonarqube-4.5.7\bin\windows-x86-64\StartSonar.bat(双击,等着,看到:Process[web] is up,就是成功了,这个窗口不要关闭)访问:http://localhost:9000查看结果。
5、下载:sonar-runner-2.4。(http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip),解压(我放在E:\tool\sonar-runner-2.4\
6、sonar-runner-2.4中查找并修改sonar-runner.properties(如果第2、3步骤,您都抄了的话,这里您也不用动)
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin
7、将E:\tool\sonar-runner-2.4\bin(就是解压路径,自己看着改吧)设置到系统环境变量path中(参考java_home, path的设置)
8、在您需要验证的项目(前面说到的TEST项目)的根目录下(.project文件同目录)添加文档:sonar-project.properties(需要改的部分红色标出,您的目录不可能和我一样吧,这里您一定要改的)
# Required metadata
sonar.projectKey=TEST
sonar.projectName=TEST
sonar.projectVersion=1.0
# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
# from the directory containing the sonar-project.properties file.
sonar.sources=java/src
sonar.libraries=WebRoot/WEB-INF/lib
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
sonar.my.property=value
9、FDS根目录下,执行:sonar-runner,等着。成功结束的话(我执行过程中遇到max_allowed_packet问题,mysql管理员执行SET GLOBAL max_allowed_packet = 2*1024*1024*10 重启后解决,一般性,各位遇不到,就不特殊说了),访问:http://localhost:9000。  
登录用户名 admin:admin。 查看结果。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在GitLab中配置Sonar,需要按照以下步骤进行操作: 1. 首先,确保已经在服务器上成功安装并运行了SonarQube。可以通过访问SonarQube的URL来验证其是否成功运行。 2. 进入GitLab的项目页面,并点击左侧菜单中的“Settings”选项。 3. 在“Settings”页面上,点击“CI/CD”选项卡,并找到“General pipelines settings”部分。 4. 在“General pipelines settings”部分,找到“Secret variables”子选项,并点击“Expand”按钮。 5. 点击“Add variable”按钮,输入以下变量信息: - Key:SONAR_TOKEN - Value:SonarQube中的访问令牌,用于连接GitLab和SonarQube。 6. 点击“Add variable”按钮以保存配置变量。 7. 返回到GitLab项目页面,并找到代码仓库中的“.gitlab-ci.yml”文件。 8. 编辑该文件,并添加以下配置信息: ```yaml sonarqube: image: sonarsource/sonar-scanner-cli script: - sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=项目标识符 ``` 其中,“项目标识符”需要替换为你在SonarQube中创建的项目标识符。 9. 保存并提交更改。GitLab会自动触发CI/CD流水线,将代码提交到SonarQube进行代码质量分析。 10. 在GitLab的项目页面上,点击左侧菜单中的“CI/CD”选项,可以查看CI/CD流水线的执行情况。 配置完成后,GitLab将会在每次代码推送到仓库时,自动触发SonarQube执行代码质量分析,并将分析结果反馈给GitLab。这样就可以更好地管理和控制代码质量,提高项目的软件开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值