SonarQube 是一個代碼品質管理的平台,關于平台的配置方法很多,但是用于Android Studio的相關文檔真心不多,使用方法:
1 本地進行代碼審查:(使用AS的插件)
缺點:無法同步到伺服器并形成圖表和文檔
優點:友善在AS中進行跟蹤定位
該使用方法過于簡單不進行描述
2 可以将結果同步到伺服器的方式:(與AS關系不大,屬于通用的方式)
優點:可以形成圖表,上傳到伺服器後友善統一管理
缺點:需要下載下傳sonar—runner,配置環境變量(非必要手段),沒有插件操
作友善
使用方法:
2. 配置 sonar-runner的config

image.png
3. 具體配置
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://xxx.xxx.xxx.xxx:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar
[email protected]
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
sonar.login=admin
sonar.password=admin
4. 在被檢查項目的根目錄建立 sonar-project.properties檔案

image.png
5. 進行配置
# Required metadata
# key 和 name 就是建立項目時輸入的字段,這裡填寫自己的項目name和key,其他不用管。
sonar.projectKey=Android
sonar.projectName=Android
sonar.projectVersion=1.0
# Path to the parent source code directory.
# 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=app/src
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
sonar.my.property=value
sonar.java.binaries=app/build/intermediates/classes
6. 編譯

image.png
1.這裡報錯是因為沒有找到對應的classes(我把項目給clearn了)
2.這裡是在項目的根目錄下打開終端(cmd)執行之前下載下傳好的sonar-runner的bin目錄下的sonar-runner
7. Success:

image.png