SonarQube, formerly known as Sonar, is a platform to analyze code quality.
Installing SonarQube
- Go to http://www.sonarqube.org/downloads/ and download the latest release.
- Unzip the archive to the directory of your choice.
Starting SonarQube
- Go to your downloaded SonarQube.
- Open bin/[folder corresponding to your OS]
- Open up a terminal window and navigate to bin/[folder corresponding to your OS]
- Now you need to execute the correspoding file in the terminal.
- Open a browser and enter localhost:9000. The sonar Dashboard should open.
It may take some time to Load.
For eg: On Mac : sh sonar.sh start (or just double click StartSonar.bat on windows).
This command will start sonar listening on localhost:9000.
Analyse Your Android Studio Project
Open Your Project’s build.gradle and add like this.
buildscript { repositories { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath "org.sonarqube.gradle:gradle-sonarqube-plugin:1.0" } }
Now open the module’s build.gradle you want to analyse and add the below script.
apply plugin: "org.sonarqube" sonarqube { properties { property "sonar.projectName", "MySampleProject" property "sonar.projectKey", "MySampleProject" property "sonar.host.url", "http://localhost:9000" property "sonar.projectVersion", "1.0" property "sonar.language", "java" property "sonar.sources", "src/main/" } }
Open your terminal in the Android Studio and execute the below command.
$ : ./gradlew sonar
You can see a series of output in the terminal and at the end You can see where the report is generated…something like this
localhost:9000/projects/MySampleProject.
All Done.
Please send your feedback to coderzheaven@gmail.com