AndroidStudio下使用SonarQube使用心得

SonarQube 是一个代码质量管理的平台,关于平台的配置方法很多,但是用于Android Studio的相关文档真心不多,使用方法:

1 本地进行代码审查:(使用AS的插件)

  缺点:无法同步到服务器并形成图表和文档
  优点:方便在AS中进行跟踪定位

该使用方法过于简单不进行描述

2 可以将结果同步到服务器的方式:(与AS关系不大,属于通用的方式)

  优点:可以形成图表,上传到服务器后方便统一管理
  缺点:需要下载sonar—runner,配置环境变量(非必要手段),没有插件操            
  作方便

使用方法:

1.下载 sonar-runner 包:http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/
2. 配置 sonar-runner的config

《AndroidStudio下使用SonarQube使用心得》 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
sonar.jdbc.password=sonar@2018

#----- 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文件

《AndroidStudio下使用SonarQube使用心得》 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. 编译

《AndroidStudio下使用SonarQube使用心得》 image.png

1.这里报错是因为没有找到对应的classes(我把项目给clearn了)
2.这里是在项目的根目录下打开终端(cmd)执行之前下载好的sonar-runner的bin目录下的sonar-runner
7. Success:

《AndroidStudio下使用SonarQube使用心得》 image.png

    原文作者:埃赛尔
    原文地址: https://www.jianshu.com/p/f37b97a9f85c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞