使用 Lint 和 SonarQube 分析 Android 项目 [英] Analyzing Android Project with Lint and SonarQube

查看:52
本文介绍了使用 Lint 和 SonarQube 分析 Android 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的有一个溢出",试图让这些东西一起工作.我按照这里的说明进行操作:http://docs.sonarqube.org/display/PLUG/Android+Lint+插件,最后得到了一个安装了 Android Lint 插件 1.1 的 SonarQube 5.1.1 服务器.然后我将我的多模块 Gradle 构建配置为与 SonarQube 插件一起使用:请参阅下面根配置中的代码片段.

I really got an 'overflow' trying to make these things to work together. I followed instruction from here: http://docs.sonarqube.org/display/PLUG/Android+Lint+Plugin and finally got a SonarQube 5.1.1 server with Android Lint plugin 1.1 installed. Then I configured my multi-module Gradle build to work with SonarQube plugin: see code fragment from root config below.

plugins {
    id 'org.sonarqube' version '1.0'
}

sonarqube {
    properties {

        property 'sonar.host.url', 'sonarqube-server:9000'
        property 'sonar.jdbc.url', 'jdbc:mysql://sonarqube-db:3306/sonar?useUnicode=true&characterEncoding=utf8'
        property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver'
        property 'sonar.jdbc.username', 'sonar'
        property 'sonar.jdbc.password', 'sonar'
        property 'sonar.sourceEncoding', 'UTF-8'
        property 'sonar.login', 'admin'
        property 'sonar.password', 'admin'

        property 'sonar.profile', 'Android Lint'

        property 'sonar.import_unknown_files', true
        property 'sonar.android.lint.report', 'build/outputs/lint-results.xml'
    }
}

然后我运行 lint sonarqubetask 来执行分析.结果,我收到了大量关于retrolambda"项目的 Lint 错误(java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression),这很正常,并且 lint-results.xml每个模块的 (随附 HTML 版本)文件,其中包含对发现的问题的描述.报告称发现了 8 个错误和 434 个警告.但是当 sonarqube 插件尝试将结果上传到 SonarQube 服务器时出现问题.日志中充满了无法找到文件"和无法找到规则"消息.当处理结束时,我的项目在 SonarQube 服务器上没有报告任何问题.

And after that I ran lint sonarqubetask to execute the analysis. As a result I got a bulk of Lint errors regarding 'retrolambda' project (java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression), which is quite normal, and lint-results.xml (accompanied with HTML version) files per each module containing descriptions of issues discovered. The report said that there were 8 errors and 434 warnings found. But things went wrong when sonarqube plugin tried to upload the results to SonarQube server. The log was full of 'Unable to find file' and 'Unable to find rule' messages. And when the processing was over, then there were no issues reported for my project on SonarQube server.

我想知道,出了什么问题?我检查了路径,所有文件都在那里.我查看了所有可以进行的讨论,似乎我的配置是正确的,而且我做的一切都是正确的.有没有人有任何线索,我错过了什么以及需要检查什么?欢迎任何建议或想法.

And I am wondering, what did went wrong? I checked the paths, and all files were there. I looked through all discussions I could reach, and it seems like my config is correct and I do everything right. Does anybody have any clue, what I missed and what needs to be checked? Any suggestions or ideas are welcome.

如果有一种方法可以使用外部 SonarQube Runner 导入 lint 数据,我也会很高兴,因为这个工具似乎比 Gradle 插件更可预测和更稳定.

I will be also happy if there is a way to import lint data using external SonarQube Runner, since this tool seems to be more predictable and stable then a Gradle plugin.

推荐答案

我在一个多模块 android 项目上取得了成功.由于完整的构建文件占用太多空间,我只在此处显示相关部分.

I had success with a multimodule android project. Since the complete build files take too much space I show the relevant parts here only.

在父项目的build.gradle我设置:

buildscript {
    ...
    dependencies { classpath 'com.android.tools.build:gradle:1.5.0'
    ...
}
plugins { id "org.sonarqube" version "1.1" }

在我设置的应用项目(和任何其他子项目)中:

In the app project (and any other children) I set:

sonarqube {
    properties {
        property "sonar.profile", "Android Lint"
        property "sonar.sources", "./src/main/java"
    }
}

这是 SonarQube 插件开始分析项目的最低设置.

That was the minimum setup for SonarQube plugin to start analyzing the projects.

这篇关于使用 Lint 和 SonarQube 分析 Android 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆