Android SonarQube
SonarQube
sonarqube is static code analysis for several languages.
How do we use?
We can use both local and serverside. A developer check codes on local and fix problems. Prepare CI and check code periodically.
And we can use it with CI such as jenkins.
Set up for database
To use sonarqube, we need to prepare database.
Sonarqube covers several Database, oracle, mysql, postresql, SQLServer …
In this time, let’s use mysql.
Steps
- Install mysql
- Create database for sonarqube
Installation part is skip.
Let’s create database named ‘sonar'(Any name is O.K., it’s just settings)
create database sonar
And setup username and password if you want
Install SonarQube
Please access SonarQube page, and download zip file according to your OS.
I download windows version 4.5.7, download and unzip.(Finished)
You can see directories under unzip directory(bin, conf, data, etc…)
To start sonarqube by command, see sonarqube/windows-x86-64
StartSonar.bat
Start sonarqube and work with localhost:9000
If you didn’t setup database, you cannot see specific data
Android Studio gradle plugin
Edit build.gradle for Project and App
build.gradle(Project)
buildscript { repositories { jcenter() maven { url "https://plugins.gradle.org/m2/" // ADD } } dependencies { classpath 'com.android.tools.build:gradle:2.0.0' classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1" // ADD } }
Add repository settins and dependencies
build.gradle(Module:app)
apply plugin: "org.sonarqube" sonarqube { properties { property "sonar.host.url", "http://localhost:9000" property "sonar.jdbc.url", "jdbc:mysql://localhost/sonar" property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver" property "sonar.jdbc.username", "sonar" property "sonar.jdbc.password", "sonar" property "sonar.language", "java" property "sonar.sources", "src/main/java" } }
Set parameters for Android, database setting should be your database environment.