【问题标题】:Sonar qube not showing results for Android LintSonarqube 未显示 Android Lint 的结果
【发布时间】:2016-12-13 18:03:32
【问题描述】:

这是我的 build.gradle,

apply plugin: 'org.sonarqube'

sonarqube {

    properties  {

        property "sonar.host.url", "http://10.52.211.255:9000/sonar"

        property "sonar.sources", "src/main/java"

        property "sonar.language", "java"

        property "sonar.profile", "Android Lint"

    }
}

代码正在运行

属性“sonar.profile”,“声纳方式”。

但我需要这个用于 android Lint。获得零结果可能是什么问题。

【问题讨论】:

标签: android android-gradle-plugin sonarqube sonarqube-4.5 sonarqube-scan


【解决方案1】:

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

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"

        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

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

【讨论】:

    【解决方案2】:

    它对我有用,并开始向声纳仪表板报告 android lint 问题:

    我的 Sonar 版本是 7.6.2

    将下方添加到声纳属性:

    property "sonar.androidLint.reportPaths", "${project.buildDir}/reports/lint-results.xml"
    

    在上面运行之后:./gradlew lint sonarqube

    它将显示在 Code Smells 部分 android:usesCleartextTraffic="true" 属性 usesCleartextTraffic 仅用于 API 级别 23 及更高级别(当前最小值为 21)android-lint

    请参阅有关如何在声纳仪表板上显示外部分析仪报告的更多详细信息。

    Import third party issues Sonar Documentation 检查 Kotlin 语言

    External Analyzer Reports

    【讨论】:

      【解决方案3】:

      Sonar Lint 不会将问题推送到 SonarQube 服务器。它旨在向开发人员提供有关本地工作区代码的即时反馈。

      要显示 Sonarqube 服务器中的问题,您需要执行声纳分析。 例如使用声纳扫描仪(以前称为声纳亚军)

      【讨论】:

        【解决方案4】:

        这些代码更改帮助我解决了这个问题。

        在 Gradle 中,

        • 我已经将 lint 文件添加到我的项目中。
        • 我在 gardle 中添加了 lintOptions。
        • 接下来在 Gradle 中为 sonarqube 添加了新属性。
        apply plugin: 'com.android.application'
        android {
            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
                // if true, only report errors
                ignoreWarnings true
            }
            compileSdkVersion 24
            buildToolsVersion "23.0.1"
            useLibrary 'org.apache.http.legacy'
            defaultConfig {
                applicationId "com.pearson.writer"
                minSdkVersion 11
                targetSdkVersion 21
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                }
            }
        }
        buildscript {
            repositories {
                maven {
                    url "https://plugins.gradle.org/m2/"
                }
            }
            dependencies {
                classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1"
            }
        }
        apply plugin: 'org.sonarqube'
        sonarqube {
            properties  {
                property "sonar.projectName", "Writer40 sonarway"
                property "sonar.host.url", "http://...:9000/sonar"
                property "sonar.sources", "src"
                property "sonar.import_unknown_files", "true"
                property "sonar.language", "java"
                property "sonar.profile", "Android Lint"
                property "sonar.android.lint.report", "/data/jenkins/workspace/SonarJobs/PearsonWriterSonar/writer40/build/outputs/lint-results-debug.xml"
            }
        }
        dependencies {
            compile files('libs/android-async-http-1.4.4.jar')
            compile files('libs/android-support-v4.jar')
            compile files('libs/libGoogleAnalyticsServices.jar')
            compile files('libs/universal-image-loader-1.7.0.jar')
        }
        
        • 接下来更改了 Jenkins 中的一些配置。(请看图片)

        • 在 jenkins 中运行声纳之前,命令运行 lint。

        然后我得到了一个与 Android Lint 相关的输出

        谢谢。

        【讨论】:

          【解决方案5】:

          您必须将分析模式提到为发布才能将结果提交到服务器。

          属性“sonar.analysis.mode”、“发布”

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-03-21
            • 2017-08-25
            • 2016-02-16
            • 2017-12-11
            • 1970-01-01
            • 2013-01-09
            • 2018-07-16
            • 2018-11-24
            相关资源
            最近更新 更多