【问题标题】:Sonar Android Lint no matching issues foundSonar Android Lint 未找到匹配问题
【发布时间】:2014-05-16 13:43:47
【问题描述】:

我遇到了以下问题:我安装了带有“Android Lint”质量配置文件的 SonarQube 和 Android 插件。当我使用“Android Lint”配置文件执行我的 build.gradle 脚本时,sonar-runner 插件运行良好,但在 SonarQube 中我看不到匹配的问题,只有零。

尽管如此,当我包含另一个配置文件时——不是“Android Lint”——我可以看到很多问题。同样在我的 android SDK 中,当应用它自己的 lint 时,我可以看到 157 个问题。它可以是什么?

声纳 - 版本 3.7.4;
android 插件 - 0.1 版

【问题讨论】:

    标签: android gradle sonarqube lint android-lint


    【解决方案1】:

    您的 sonar.sources 属性应指向 AndroidManifest.xml 文件的根目录。例如。如果您的 AndroidManifest.xml 文件位于 src/main 中,那么您的 build.gradle 文件应包含:

    sonarRunner {
        sonarProperties {
            ...
            property "sonar.sources", "src/main"
            property "sonar.profile", "Android Lint"
            ...
        }
    }
    

    如果您需要sonar.sources 中的更多路径,您可以将它们作为逗号分隔的列表。

    您可以在其source code 中找到 Sonar Android 插件如何确定是否运行分析。

    【讨论】:

      【解决方案2】:

      像这样更改您的声纳属性:

      apply plugin: "org.sonarqube"
      
      sonarqube {
      
      properties {
      
          property "sonar.projectName", "appa"
      
          property "sonar.projectKey", "appa_app"
      
          property "sonar.projectVersion", "1.0"
      
          property "sonar.analysis.mode", "publish"
      
          property "sonar.language", "java"
      
          property 'sonar.sourceEncoding', "UTF-8"
      
          property "sonar.sources", "./src/main"
      
          //property "sonar.exclusions", "**/*Entity.java"
      
        //  property "sonar.exclusions", "src/main/java/com/apparkb/model/**, **/*Entity.java"
      
          property "sonar.host.url", "http://192.168.21.33:9000"
      
          property "sonar.login", "admin"
      
          property "sonar.profile", "testlint"//use your quality profile instead
      
          property 'sonar.import_unknown_files', true
      
          property "sonar.android.lint.report", "./build/outputs/lint-results-debug.xml"
      
          property "sonar.password", "admin"
      
          property "sonar.java.binaries", "build/"
      
      
      
      }
      }
      

      要创建 lint-results-debug.xml,您必须在工作室终端上运行以下命令:

      ./gradlew lint
      

      它将生成丢失的 XML 报告。注意,它可以为每个构建变体生成报告(Debug 默认会生成 build/outputs/lint-results-debug.xml)。因此,您可以调用 lintDebug、lintRelease...,具体取决于您的构建变体。

      并将 lint 属性更改为:

      lintOptions { // set to true to turn off analysis progress reporting by lint
      
          quiet true
      
          // if true, stop the gradle build if errors are found
      
          abortOnError false
      
          // do not ignore warnings
      
          warningsAsErrors true
      }
      

      现在如果你运行

      ./gradlew sonarqube
      

      您将得到显示的结果,它实际上是实际托管在服务器上的本地文件报告

      【讨论】:

      【解决方案3】:

      不幸的是,如果您只是将 sonar.sources 指向 src/main,那么您的所有源代码都会出现问题,因为您很可能没有设置 minSdkVersion 和 targetSdkVersion 集(它来自 gradle)。我尝试将我的来源设置为:

      build/intermediates/bundles/release,src/main/java

      但由于 API 级别,我仍然收到大量(无效)错误。

      【讨论】:

      • 您能找到最终的解决方案吗?
      • 不,我们在 Hudson/Jenkins 中使用 LINT 输出,并使用 Sonar 进行传统的非 Android 分析。有点烂,但就是这样。
      猜你喜欢
      • 2017-10-19
      • 1970-01-01
      • 2016-04-16
      • 2018-03-02
      • 2017-12-14
      • 1970-01-01
      • 2020-01-06
      • 2012-04-26
      • 1970-01-01
      相关资源
      最近更新 更多