3

enter image description here

This is my 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"

    }
}

the code is working for

property "sonar.profile", "sonar way".

But I need this for android Lint. What can be the issue with getting zero results.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Please refer to http://stackoverflow.com/questions/37831982/sonar-profile-is-deprecated-for-4-5-4-sonarqube. Looks like **sonar.profile** is deprecated and we may need to set the profile directly from UI. –  Aug 08 '16 at 04:20

5 Answers5

3

It worked for me and started reporting android lint issues to sonar dashboard:

My Sonar version is 7.6.2

Add Below to sonar properties:

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

After changing above run: ./gradlew lint sonarqube

It will show in Code Smells section android:usesCleartextTraffic="true" attribute usesCleartextTraffic is only used in API level 23 and higher (current min is 21) android-lint

Please refer for more details on how to show external analyzer reports to sonar dashboard.

Import third party issues Sonar Documentation Check for Kotlin Language

External Analyzer Reports

JJD
  • 50,076
  • 60
  • 203
  • 339
takharsh
  • 2,258
  • 1
  • 21
  • 26
2

change your sonar properties like this:

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



    }
}

For creating lint-results-debug.xml you will have to run the below command on studio terminal:

./gradlew lint

It will generate the missing XML report. Be carful, it can generate a report for each build variant (Debug by default will generate build/outputs/lint-results-debug.xml). So you can call lintDebug, lintRelease... dependings on your build variant.

And change the lint properties to:

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
    }

now if you run ./gradlew sonarqube

you will get the results shown its actually the local file report that's actually getting hosted upon the server

a screen shot after analysis

Amal p
  • 2,882
  • 4
  • 29
  • 49
1

Sonar Lint does not push the issues to SonarQube server. It is meant to give instant feedback to developer on the code in local workspace.

To show issues in Sonarqube server, you need to perform a sonar analysis. For example using sonar scanner(previously known as sonar runner)

Gautam Jose
  • 686
  • 8
  • 20
0

This codes changes helped me to solve this problem.

In Gradle,

  • I have already added lint files to my project.
  • I added lintOptions to gardle.
  • Next added new properties to sonarqube in Gradle.
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')
}
  • Next changed some configurations in the Jenkins.(please look the image)

enter image description here

  • Before run the sonar in jenkins ,Command to run the lint.

then I got a out put related to Android Lint

Thanks.

0

You have to mention analysis mode as publish to submit the results to the server.

property "sonar.analysis.mode", "publish"

Anjula
  • 1,690
  • 23
  • 29
  • sonar.analysis.mode has been dropped and can not be used anymore. Not sure which version but already long time ago. – lilienberg Feb 02 '23 at 10:46