SonarQube安装/使用 on Mac环境

准备工作

JDK (忽略)

Mysql (忽略)

SonarQube 

https://www.sonarqube.org/downloads/

Sonar-Scanner

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

Notes:

下载Community Edition 版本的SonarQube, 因为它是Free & Open Source

安装

1. 下载SonarQube之后,打开bin目录下的对应OS文件夹

cd /Users/cli/tool/sonarqube-7.6/bin/macosx-universal-64

[cli@cli-mac:macosx-universal-64] sh sonar.sh start

Starting SonarQube...

Started SonarQube.

2. 打开浏览器,访问SonarQube:http://localhost:9000, 可以看到启动页面

3. 配置

3.1 打开mysql, 并创建数据库,数据库名称可以任意指定,这里以数据库名为sonar来举例

CREATE DATABASE IF NOT EXISTS sonar;

3.2 进入SonarQube安装目录,并编辑conf下的sonar.properties文件

cd /Users/cli/tool/sonarqube-7.6/conf

在sonar.properties文件中mysql下添加如下信息

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

sonar.jdbc.username=root

sonar.jdbc.password=root

sonar.sorceEncoding=UTF-8

sonar.login=admin

sonar.password=admin

sonar.jdbc.url是你的mysql数据库连接url,sonar.jdbc.username是mysql数据库用户名,sonar.jdbc.password是数据库用户密码,sonar.login是SonarQube的登录用户名,sonar.password是SonarQube的登录密码。

3.3 重启SonarQube服务

ccli@ccli-mac:macosx-universal-64$ sh sonar.sh restart

Stopping SonarQube...

Waiting for SonarQube to exit...

Stopped SonarQube.

Starting SonarQube.

3.4 打开浏览器,再次访问SonarQube:http://localhost:9000,会稍微有点慢,因为需要初始化SonarQube数据库 

4 安装sonar scanner

1. brew install sonar-scanner 

2. 应用准备工作中下载的binary  路径为 /Users/cli/tool/sonar-scanner-3.3.0.1492-macosx/bin

export PATH=/Users/cli/tool/sonar-scanner-3.3.0.1492-macosx/bin:$PATH

5.  在你想要分析的code 路径下添加配置文件sonar-project.properties ,配置文件内容如下

#----- Default SonarQube server

sonar.host.url=http://localhost:9000

# must be unique in a given SonarQube instance

sonar.projectKey=api_transaction

# this is the name and version displayed in the SonarQube UI. 

sonar.projectName=api_transaction

sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.

# This property is optional if sonar.modules is set.

sonar.sources=.

# Encoding of the source code. Default is default system encoding

#sonar.sourceEncoding=UTF-8

sonar.exclusions=**/*_test.go,**/proto/**

sonar.go.coverage.reportPaths=report/cover-all.cov

sonar.go.golint.reportPaths=report/golint-report.out

6. 运行sonar-scanner

[cli@cli-mac:transaction$] sonar-scanner

运行最后,会出现这种信息表示成功

7. click http://localhost:9000/, 选中Projects -> All -> 你的项目名,比如api_transaction, 会出现这个页面


然后,你可以Click Code Smells上的6, 可以发现code不合适之处,按照提示进行修正,其它比如Duplications也是类似

你可能感兴趣的:(SonarQube安装/使用 on Mac环境)