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

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

问题描述

我真的有一个'溢出'试图让这些东西一起工作。我遵循这里的指示: http://docs.sonarqube.org/display/PLUG/Android+Lint+插件,最后得到一个安装了Android Lint插件1.1的SonarQube 5.1.1服务器。然后我将我的多模块Gradle构建配置为与SonarQube插件配合使用:请参阅下面root配置的代码片段。

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

sonarqube {
属性{

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

属性'sonar.profile','Android Lint'

属性'sonar.import_unknown_files',true
道具erty'sonar.android.lint.report','build / outputs / lint-results.xml'
}
}

之后,我运行 lint sonarqube 任务执行分析。因此,我得到了大量有关'retrolambda'项目( java.lang.UnsupportedOperationException:未知的ASTNode子项:LambdaExpression )的Lint错误,这是非常正常的,并且<$每个模块包含c $ c> lint-results.xml (附带HTML版本)文件,其中包含发现问题的描述。该报告称,发现8个错误和434个警告。但sonarqube插件尝试将结果上传到SonarQube服务器时,出现了问题。日志满了'无法找到文件'和'找不到规则'消息。当处理结束后,SonarQube服务器上的项目没有报告问题。



我想知道,出了什么问题?我检查了路径,并且所有文件都在那里。我仔细查看了所有可能达到的讨论结果,似乎我的配置是正确的,我做的都是正确的。有人有任何线索,我错过了什么,需要检查什么?欢迎任何建议或想法。



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

解决方案

我已经成功使用了多模块android项目。由于完整的构建文件占用了太多空间,因此我仅在此处显示相关部分。



在父项目的 build.gradle 中,我设置了

  buildscript {
...
依赖关系{classpath'com.android.tools.build:gradle: 1.5.0'
...
}
plugins {idorg.sonarqubeversion1.1}

在应用程序项目(以及任何其他子项)中,我设置了:

  sonarqube {
属性{
属性sonar.profile,Android Lint
属性sonar.sources,./src/main/java
}
}

这是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&amp;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'
    }
}

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.

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.

解决方案

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

In the parent project's build.gradle I set:

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"
    }
}

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

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

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