Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube plugin with Android Studio

Has anyone succeeded in getting either the SonarQube Community IntelliJ plugin OR the 'official' SonarQube IntelliJ plugin to show results of static code analysis in Android Studio projects?

The second of these requires Maven but the first of these is supposed to be agnostic.

Somehow I managed to run a sonarRunner on my project in the past but I can't manage to do it now. But there's not much point in getting that working again if I can't see my results in the IDE.

like image 550
Merk Avatar asked Nov 10 '14 22:11

Merk


1 Answers

Short answer: yes you can using the SonarQube Community IntelliJ plugin

Long answer:

assuming you have a build.gradle like:

apply plugin: "sonar-runner"

sonarRunner {
    sonarProperties {
        // can be also set on command line like -Dsonar.analysis.mode=incremental
        property "sonar.host.url", "http://your.sonar.server:9000"
        property "sonar.analysis.mode", "incremental" 
        property 'sonar.sourceEncoding', 'UTF-8'
        property 'sonar.language', 'java'
        property 'sonar.profile', 'my_profile'
    }
}

subprojects {
    sonarRunner {
        sonarProperties {
            properties["sonar.sources"] += "src/main/java"
        }
    }
}

....

then you can run local sonar analysis with gradle:

$ ./gradlew sonarRunner

this will produce a sonar-report.json file:

$ cat build/sonar/sonar-report.json

Now you have everything is needed by the plugin:

  • SonarQube server
    • Name: your_server
    • Host url: http://your.sonar.server:9000
  • Local analysis script
    • Name: gradle script
    • Script: /path/to/android-studio-example-project/gradlew sonarRunner
    • Path to sonar-report.json: /path/to/android-studio-example-project/build/sonar/sonar-report.json

After the configuration is done you can see new issues by running the SonarQube (new issues) inspection inside Intellij (Android Studio)

I have used this project for an example:

https://github.com/sonar-intellij-plugin/android-studio-example-project

and sonarqube server 4.0 with a squid only based rule set (4.4 failed to analyse a gradle project)

like image 54
Oleg Majewski Avatar answered Sep 19 '22 12:09

Oleg Majewski