1、下载sonarqube-5.2.zip
https://www.sonarqube.org/downloads/
2、创建数据库
CREATE DATABASE sonar CHARACTER SET utf8COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
--@%支持远程访问
GRANT ALL ON sonar.* TO 'sonar'@'%'IDENTIFIED BY 'sonar';
--本地访问
GRANT ALL ON sonar.* TO 'sonar'@'localhost'IDENTIFIED BY 'sonar';
FLUSHPRIVILEGES;
3、编辑C:\Users\zhilin\Desktop\sonarqube-5.2\conf\sonar.properties配置数据库
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
备注:url是数据库连接地址,username是数据库用户名,jdbc.password是数据库密码,login是sonarqube的登录名,sonar.password是sonarqube的密码
4、下载sonar-l10n-zh-plugin-1.8.jar汉化sonar,sonar-l10n-zh-plugin-1.8.jar文件放到目录
C:\Users\zhilin\Desktop\sonarqube-5.2\extensions\plugins
5、启动D:\ng_tomcat\sonarqube-5.2\bin\windows-x86-32\ StartSonar.bat
6、访问http://localhost:9000
7、配置
步骤:
8、安装完毕
9、下载sonar-runner(sonar的命令行分析端软件有两种分别是Runner和Scanner,官网文档中写的是Scanner,但Runner和它安装、使用都基本一致。)
http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/
10、 解压sonar-scanner-2.5.zip,并修改配置
D:\ng_tomcat\sonar-scanner-2.5\conf\sonar-runner.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sourceEncoding=UTF-8
sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=admin
11、 在命令行运行以上命令并回显,表示运行成功
C:\Users\zhilin> D:\ng_tomcat\sonar-scanner-2.5\bin\sonar-runner–h
或者
C:\Users\zhilin> D:\ng_tomcat\sonar-scanner-2.5\bin\sonar-runner–version
12、 打开要进行代码分析的项目根目录,新建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 directorycontaining
#the sonar-project.properties file.
sonar.sources=src
#Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
备注:其中:projectName是项目名字,sources是源文件所在的目录
13、设置成功后,启动sonarqube服务,并启动cmd;在cmd进入项目所在的根目录,输入命令:sonar-runner,分析成功后会出现下图
14、打开http://localhost:9000/,我们会看到主页出现了分析项目的概要图
标签:jdbc,runner,sonarqube,sonar,password,安装,localhost From: https://blog.51cto.com/u_13538361/6404157