SonarQube Plugin with Android Studio

Has anyone succeeded in getting either the SonarQube IntelliJ community plugin or the “official” SonarQube IntelliJ plugin to show static code analysis results in Android Studio projects?

The second one requires Maven, but the first one must be agnostic.

Somehow I managed to run sonarRunner in my project in the past, but I can not do it now. But there isn’t much point in working again if I don’t see my results in the IDE.

+6
source share
3 answers

Short answer: yes, you can use the SonarQube IntelliJ community plugin

Long answer:

Assuming you have build.gradle, for example:

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 start local sonar analysis using gradle:

 $ ./gradlew sonarRunner 

this will lead to the creation of a sonar-report.json file:

 $ cat build/sonar/sonar-report.json 

Now you have everything you need for the plugin:

  • SonarQube Server
  • 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 setup is complete, you can see new problems by checking SonarQube (new problems) inside Intellij (Android Studio)

I used this project as an example:

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

and sonarqube server 4.0 with a set of rules for squid only (4.4 could not parse the gradle project)

+9
source

Sonar Runner is deprecated and replaced by Sonarqube Scanner.

After satarizing sonarqube on your system, you need to add the sonarqube plugin to the gradle application module of your project.

 plugins { id "org.sonarqube" version "2.2.1" } 

Then define the Sonarqube properties for your project and synchronize your project.

 sonarqube { properties { property "sonar.projectName", "SonarqubeDemo" property "sonar.projectKey", "SQKey" property "sonar.sources","src/main/java" property "sonar.language","java" property "sonar.sourceEncoding", "UTF-8" // property "sonar.exclusions", "src/main/java/com/foo/Foo.java" } } 

After creating or synchronizing the project, open Command Prompt and go to the application directory where your gradle file is located.

Run gradle sonarqube and wait for build to complete

Below is a post link that gives a full detailed explanation of the integration of sonarqube with the sonarbebe scanner in Android.

Integration and understanding of SonarQube in Android

0
source

Open Android Studio

File -> Preferences -> Plugins -> then enter sonarqube and click "Browse Repositories" at the bottom.

Restart Android Studio.

right click on the project -> Analysis -> Sonarlint -> Analyze all files with Sonarlint

Results will be displayed in the Sonarlint view below.

0
source

Source: https://habr.com/ru/post/978001/


All Articles