Articles → SONARQUBE → Run Sonar Scanner
Run Sonar Scanner
Android Project
package com.example.demo_application;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("METHOD", "onCreate called");
}
@Override
protected void onStart() {
super.onStart();
Log.v("METHOD", "onStart called");
}
@Override
protected void onResume() {
super.onResume();
Log.v("METHOD", "onResume called");
}
@Override
protected void onPause() {
super.onPause();
Log.v("METHOD", "onPause called");
}
@Override
protected void onStop() {
super.onStop();
Log.v("METHOD", "onStop called");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("METHOD", "onDestroy called");
}
@Override
protected void onRestart() {
super.onRestart();
Log.v("METHOD", "onRestart called");
}
}
Sonar Scanner Properties File
sonar.host.url=http://localhost:9000
sonar.sourceEncoding=UTF-8
sonar.projectKey=android-sample-1
sonar.projectName=Sonar_demo_project_1
sonar.projectVersion=1.0
sonar.scm.disabled=True
sonar.sources=src/main/java
sonar.language=android
sonar.java.binaries=build/outputs/apk/debug
- First line specifies the URL of the sonarqube server.
- Second line specifies the encoding used in the source code.
- Third parameter is the project key, which is the unique id given to the project.
- Fourth parameter is the project name.
- Fifth parameter is the version of code.
- Sixth parameter is the path of source code.
- Seventh parameter is the language in which your code is written.
Run Sonar Scanner
- Open powershell.
- Go the path of sonar-project.properties file using cd command.
- Run the following command.
Click to Enlarge
Check The Result
- Go to http://localhost:9000
- Login to the server using ‘admin’ as user name and ‘admin’ as password.
- On the home page, you can see the project scanned
Click to Enlarge
- Click on the project name (‘Sonar_demo_project_1’ in this case)
- In the detail screen, you can see the results of scan in more categorized way
Click to Enlarge
- Click on the any category (like we can click on ‘Code Smells’ in this case).
- You can see the list of issues
Click to Enlarge
- You can click on the issue to get more details
Click to Enlarge