Sonarqube is a server-side static code analyzer tool. It is very useful to write clean and high-quality code. You must have sonarqube running on the local host or server. Create a new project giving a name and a unique identifier, this name and uniqueness, which we will use to identify us on the server along with our username and password. On the server side, you need to configure several things, for example -
- Create a user.
- Create a new project with a unique identifier.
Now in the Android studio we will use the gradle sonarqube command to analyze our project using sonarqube.
Before running the sonarqube gradle command, you must complete the following steps:
- First we need to install gradle on our computer.
- (Optional) To install the sonarqube plugin in android studio. Switch to -
File → Settings → Plugins → then enter sonarqube and click on Browse Storage below.
Open the build.gradle file, add the sonarqube.org plugin and add the following properties -
apply plugin: "org.sonarqube" sonarqube { properties { property "sonar.projectName", "MyProject" property "sonar.projectKey", "com.example.myproject" property "sonar.host.url", "http://192.114.1.1:9000" property "sonar.language", "java" property "sonar.sources", "src/main/" property "sonar.login", "username" property "sonar.password", "password" } }
Open the gradle project file and in add dependencies -
dependencies { classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1" }
And in the add store -
allprojects { repositories { maven { url "https://plugins.gradle.org/m2/" } } }
Now on the studio side of Android, your setup is complete, run the gradle sonarqube command to perform the analysis.
If you work in a team and want to create separate branches for all developers, run gradle sonarqube -Dsonar.branch = {YouName}
source share