移动测试基础 [深入浅出 Android 自动化测试] 第三篇:使用 SonarQube 对代码进行静态扫描分析

大海 · 2017年10月12日 · 最后由 OBJ 回复于 2018年03月12日 · 2558 次阅读

背景概述

随着 IT 行业中软件产品的推陈出新,客户对于软件产品的要求也越来越高,因此如何高质量的管理软件代码,及时地对代码质量进行分析并给出合理的解决方案就成为了当下必须要解决的一个问题。与当今众多的代码质量管理工具相比,SonarQube 更具有特色和竞争力,其优势主要体现为:它是一个开源的代码质量管理系统,支持 25+ 种语言,可以通过使用插件机制与 eclipse 和 JIRA 等其他外部工具集成,从而实现了对代码的质量的全面自动化分析和管理。

SonarQube 介绍

  • SonarQube 可以支持 25+ 种编程语言,针对不同的编程语言其所提供的分析方式也有所不同:
  • 对于所有支持的编程语言,SonarQube 都提供源了代码的静态分析功能;
  • 对于某些特定的编程语言,SonarQube 提供了对编译后代码的静态分析功能,比如 java 中的 class file 和 jar 和 C# 中的 dll file 等;
  • 对于某些特定的编程语言,SonarQube 还可以提供对于代码的动态分析功能,比如 java 和 C# 中的单元测试的执行等。

SonarQube 的服务架构

image

SonarQube 的安装

SonarQube 的运行

启动 SonarQube 控制台

启动 Sonar-scanner 执行代码扫描


打开控制台查看扫描结果



资料参考:

报错问题集合

最终解决方法

https://stackoverflow.com/questions/21204350/sonar-setup-undefined-mandatory-properties

https://stackoverflow.com/questions/26092773/sonar-you-must-define-the-following-mandatory-properties-for-unknown-not-resolv

https://stackoverflow.com/questions/30237547/sonarqube-typescript-plugin-you-must-install-a-plugin-that-supports-the-langua

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 4 条回复 时间 点赞
wangpengfei100 回复

是怎么解决的呢
需要装 sonar.java.binaries 插件么

大海 回复

谢谢大神,解决了。我在配置项中少了个参数

wangpengfei100 回复

The error message says:

Error during SonarQube Scanner execution org.sonar.squidbridge.api.AnalysisException:
Please provide compiled classes of your project with sonar.java.binaries property

It seems like the java sensor requires the .class files, in addition to the .java files.

You could:

  • Add those files to the analysis (it will by the way give you more valuable sonar findings!)
  • Try adding and removing files to find out, which piece of code causes the issue and report it as a Sonar Java bug

我的 sonar runner 在对本地安卓项目进行测试的时候,总是失败,报错如下,可以帮看看怎么解决吗?
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3.184s
INFO: Final Memory: 52M/336M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
at org.sonar.java.JavaClasspath.init(JavaClasspath.java:59)
at org.sonar.java.AbstractJavaClasspath.getElements(AbstractJavaClasspath.java:281)
at org.sonar.java.SonarComponents.getJavaClasspath(SonarComponents.java:141)
at org.sonar.java.JavaSquid.(JavaSquid.java:83)

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册