Oracle ADF and Gradle integration – part#2: SonarQube

Oracle ADF and Gradle integration – part#2: SonarQube

SonarQube is an open-source platform for continuous inspection of code quality. It’s one of ‘must have’ tools in every software development company. This tutorial helps you to integrate any Java based application (in this case Oracle ADF) with Sonar using one of Gradle plugins.

Objectives

In this tutorial you will learn how to:

  • create fully functional SonarQube container using docker-compose.
  • perform static code analysis of Oracle ADF using Gradle.

 

Before you start

For a better understanding of this guide, I recommend you read my previous post:

 

I. Creating SonarQube container

Current version of SonarQube requires database to store analysis data. The creation of two separate containers and their synchronization can be somewhat cumbersome. We can use Docker Compose to make it easier. It is is a tool for defining and running multi-container applications.

 

Docker Compose installation

At first, make sure you have docker installed correctly (here you can find how to properly install docker on linux OS). Install docker-compose tool by running command:

 

Creating docker-compose.yml file

Docker Compose requires docker-compose.yml file with is a definition of multi-container environment. More about the file structure you can find on the project website. For the purposes of this tutorial I used official SonarSource docker-compose recipe.

Create an empty directory with  docker-compose.yml file like below:

The environment described in the recipe consists of two containers (PostgreSQL database and SonarQube) connected to internal sonarnet network. SonarQube is exposed on port 9000 .

 

Starting/Stopping environment

Familiarize yourself with the following commands:

Go to the directory where you created docker-compose.yml file and run:

After successful run you can stop environment by pressing Ctrl+c .

 

Logging in to SonarQube

Run environment as daemon by adding -d switch:

Wait a few seconds and open http://localhost:9000 .

Now you can Log in. Default SonarQube username/password is admin/ admin.

 

II. Create Oracle ADF application

You can use your own application or just download sample application. If you use your own application remember to integrate it with Gradle  as I showed you in this post.

The sample application contains standard ADF Model/ViewController application and it is integrated with Gradle. The ViewController project contains SampleBean class which will be analysed by SonarQube.

 

III. Configure Gradle project

Now it’s time to integrate SonaQube with Gradle project. In this tutorial I’ll use  org.sonarqube plugin. More about the plugin you can find at the official site.

Go to adf-gradle  directory and edit build.gradle file. Add plugin repository and classpath dependency to sonarqube-gradle-plugin at the beginning of the file (lines:1-14). After that just apply  org.sonarqube plugin before group property (line 17).

 

Sonar configuration

After added org.sonarqube  plugin we have to provide some sonar properties:

  • sonar.host
  • sonar.projectKey
  • sonar.projectVersion
  • sonar.language – you can specify only one language (i.e. xml, java). Leave it empty for multi-language project
  • sonar.projectBaseDir – all analysed sources have to be inside projectBaseDir
  • sonar.binaries – coma separated paths to generated artefacts
  • sonar.sources – coma separated paths to the sources of application
  • more you can find at the official SonarQube website.

 

Task order

You can also add task order dependency (line 2). This will ensure the right order of task execution. If you want to enforce assemble before sonarqube task you can add line 3.

 

After all modifications your build.gradle file should look like below:

 

Performing Sonar analysis

Make sure that you have SonarQube service started. Run gradlew tasks  command. As you can see new task appeared.

 

To perform clean, build and SonarQube analysis run:

You may also run ./gradlew sonarqube  to perform only sonar analysis without project assembling. After few seconds you will see  BUILD SUCCESSFUL message like below:

 

Go to http://localhost:9000/  and watch the results.

 

You can download the final version of application from here.

If you think this tutorial is valuable, please leave me +1  or share it. This action will allow me to reach a wider audience.

Thank you.

3
Leave a Reply

avatar
2 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Oracle ADF and Gradle integration – part#3: Dependency Management – Better-CodingSudheerArthur Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Arthur
Guest
Arthur

Great job!

Sudheer
Guest
Sudheer

Nice post!

trackback

[…] Oracle ADF and Gradle integration – part#2: SonarQube […]

Close Menu