原文地址:https://www.cnblogs.com/qiumingcheng/p/7253917.html
主要记录下遇到问题的地方:
1、下载地址:
sonarqube:http://www.sonarqube.org/downloads/
Scanner:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-windows.zip
可能是原文中的Scanner版本过低,项目中采用的是jdk版本为 1.8.0_66
2、sonarqube的登录名和密码默认为admin
3、本地汉化没有安装,不过不影响使用
4、打开Sonar Scanner根目录下的/conf/sonar-scanner.properties文件,配置如下:
mysql节点下输入以下信息
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqubetest?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.host.url=http://localhost:9000 //sonar.host.url配置的是SonarQube服务器的地址,如果测试项目与服务器不在同一台机子,则需要添加服务器的IP
5、
打开要进行代码分析的项目根目录,新建sonar-project.properties文件,配置如下:
# must be unique in a given SonarQube instance
sonar.projectKey=myProject
# 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=src
sonar.java.binaries=target
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
注意:sonar.java.binaries=target 为项目编译后的class文件存放地址
6、设置完后,打开cmd面板,进入项目根目录下,然后输入“sonar-scanner”命令,执行代码分析