Code Quality: SonarQube + Java + MySQL + Maven

Nowadays there is a several demand for programmers in the software industry, but in the last decade the software industry is looking for software engineers instead of programmers.

But, What is the difference between a programmer and a software engineer?

Basically the programmer only will focus on code/write the requirements provided by the analyst or the BA (Business Analyst).

On another hand the software engineer will be involved in several tasks like: requirement gathering, analyse and design, system architecture, prototyping or POC (Prof Of Concept), coding, feedback from the client, troubleshooting, deployment, application profiling, quality assurance, code quality, testing, team leading, bug tracking, etc.

So, in this post I will show you how to setup a very useful tool called SonarQube in order to manage code quality .

SonarQube Installation

Open the next link and download the latest version of SonarQube (for this tutorial we will use version 6.2)

Unzip the file downloaded and you should see a folder structure like this.

MySQL Configuration

  1. Create a new MySQL Schema called sonar
  2. Edit the properties sonar.jdbc.username, sonar.jdbc.password and sonar.jdbc.url in [sonar_qube_root_folder]/conf/ file with the next values

Note: Obviously the user and password values can be different based on your own configurations.

Launch SonarQube (it applies for windows-x86–32)

  1. Go to [sonar_qube_root_folder]/bin/[architecture]/StartSonar.bat
  2. Go to http://localhost:9090/
Expected Output

3. Press Login button and type the default SonarQube credentials (admin/admin)

Expected Output

In the next link you can refer the complete documentation to setup SonarQube with a different database.

Integrate with Maven

Open your maven settings file(settings.xml) located in [maven_home]\conf\ and add the next information.

  1. Open your terminal or command line
  2. Go to your maven project (where the pom.xml file is located)
  3. mvn clean
  4. mvn install
  5. mvn sonar:sonar

SonarQube UI

Go to your local SonarQube instance in order to see the quality code report.

  1. Open http://localhost:9000
  2. Type the default admin credentials (admin/admin)
  3. Feel free to play with the UI in order to discover how useful is this tool :)

Use the “Rules” tab in order to manage your quality code rules.

Here the complete SonarQube documentation

That’s all folks, if you have any feedback or question feel free to share your thoughts.