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/ 就可以看到代码分析结果。

 

以上是亲自手动实验成功的

posted @ 2017-07-10 17:06  繁体字  阅读(5453)  评论(1编辑  收藏  举报