How to Configure Bamboo and SonarQube to Use JaCoCo

How to Configure Bamboo and SonarQube to Use JaCoCo

Code Coverage Nightmare

With this blog I want to share with you my opinion about using  SonarQube for observing your project. It’s a really good idea to watch all teamwork related to commits, unit test results, bugs, issues and vulnerabilities visualized  in one single dashboard.


In а few minutes you can download, configure and run SonarQube, connect it to your Bamboo server and show reports. I have wasted days to research how to configure the code coverage functionality in my SonarQube server and I would like to share this research with you.

What Is Coverage Report


The Coverage report is the one which can help every product owner check in а few minutes how many unit tests are implemented for the project. Below the table you can see the chart showing the complexity of each class in your project and the unit test coverage.

The most used tool for showing coverage is JaCoCo reports.

Configuring Project

First Of All (And Most Important)

You need to commit a file even with one parameter. If this file doesn’t exist in your project, Bamboo will get the default .properties file and will replace all your command line parameters described below!

#—– Default SonarQube server




Test Classes

First of all you need to write some Unit tests which will prepare the coverage report. In my application I created a different Tests Project where I placed all the unit tests.

For this example I created a simple unit test for testing a DTO class with three getter methods and one constructor.


You need to add one Tests class with annotations to the tests classes you want to test. As you can see it’s not necessary to create the tests classes in the tests module.


Ant Build

Then you can use your preferred build tool (In my case it is Ant) to do the tests.

Execute the next steps:

  1. Add new build file;
  2. Configure the JaCoCo;
  3. Build the project (It’s important because in other case the build will fail);
  4. Build the tests;



Configuring Bamboo

You need to create a build plan with configured task for the sonar dashboard:


  1. Source Code Checkout – this is GIT or other subversion control task for cheking out the latest version of your source code;
  2. Script – I had to do project build for creation of all .classes files. My set of commands is:
  • cd InvoiceManagement
  • export bamboo_release=echo "${bamboo.planRepository.branch}" | cut -d/ -f2
  • /opt/Oracle/Middleware- -buildfile ojdeploy-DataServices.xml -basedir ${}/InvoiceManagement -define customdir=${}/InvoiceManagement,version=$bamboo_release-${bamboo.buildNumber}
  1. Ant – This is the Ant task with the next file and target. Here is very important to put the Specify custom results directories property with your tests directory:
    a. Build file:
    b. Target: clean test -f
    -DjavacDebug=on -DoracleHome=/opt/Oracle/Middleware/jdeveloper/
    -DjavacNowarn=off -DmiddlewareHome=/opt/Oracle/Middleware/
    c. Specify custom results directories:
  2. SonarQube Runner – this is the task which holds the magic. The most important part is the Additional parameters section:

You have to commit in your project!


#The build number


#The folder with the compiled files


#the folder with coverage reports


#file with the coverage report

#the name of used plugin

#The folder with the compiled files (for comparisson)


The following points are my personal benefits which I have discovered during my Code Coverage task with SonarQube:

    1. You are stimulating your team to write Unit Tests;
    2. You are checking if your team writes some Unit Tests;
    3. You are checking if these Unit Tests are successful;
    4. You are checking your team’s code quality (Sonar’s quality profiles are well done and you can include/exclude some rules for the team/project);
  • Write your benefit here.


SonarQube is a great tool and it should be part of the software stack in every professional team.

Teodor Ognianov

Qualified IT professional focused on software development having rich background with Oracle technologies. Deep knowledge in Business Intelligence, It project management. Familiar with broad set of Java EE frameworks, including Oracle ADF, database servers as Oracle Database (9i, 10g, 11g), Database Replications, Heterogeneous Service. Teodor is a team player with good coaching skills, providing assistance with patience and deep understanding of knowledge sharing. Responsible and highly motivated.

More Posts - Website

Follow Me:
LinkedInGoogle PlusReddit

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!