1. 程式人生 > >Sonar基礎配置及使用

Sonar基礎配置及使用

comm run utf-8 not module unique href 5.1 https

首先說下我的使用版本:

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

以上是親自手動實驗成功的

Sonar基礎配置及使用