Installation (Mac OS X)
Download SonarQube and SonarQube Runner : http://www.sonarqube.org/downloads/
Go into your SonarQube installation folder, then uncomment the following lines:
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar
Once both are installed, make sure MySQL is running on your system (mysqld in terminal). If MySQL is not installed, you can install it easily via Homebrew.
Connect to mysql using : mysql -u root -p
Then enter:
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'sonar' IDENTIFIED BY 'sonar'; GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar'; GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar'; FLUSH PRIVILEGES;
This will create the database for SonarQube. Now run the database setup page: http://localhost:9123/setup.
SonarQube is ready to go at http://localhost:9123 – login with admin/admin if you need to delete/edit project.
Running SonarQube with Android modules
Create a file named “sonar.properties” in the root folder of the module, with the following content:
sonar.host.url=http://localhost:9123 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.projectKey=project_unique_key sonar.projectName=Project Name sonar.projectVersion=1.0 sonar.sources=src/main/java sonar.language=java sonar.profile=Sonar way sonar.sourceEncoding=UTF-8
And add in build.gradle :
apply plugin: 'sonar-runner'
Another gotcha is the quality profile. Android Lint is a Java language quality profile. When this runs, no other Java language quality profile is invoked. Now Android Lint has only android-specific rules and not the java rules. The fix for this is to have Android Lint inherit from another java profile (Sonar way with findbugs in our case). Go to http://localhost:9123 then Quality Profiles > Android Lint > Inheritance and add Sonar way.
Due to a bug with the Sonarqube Android plugin (as of July 2015), Lint is not run automatically. Sonarqube will read from build/outputs/lint-results.xml by default. This is why we trigger it just before calling sonarRunner:
gradle lint sonarRunner.
After compilation, all analysis will be available at : http://localhost:9123