Setting up the Grails Project with SonarQube

Posted By : Hitesh Arora | 04-Mar-2015
Following are the steps to configure sonarqube for your grails project
1.Download SonarQube/Runner : Download the sonarqube as well as sonarrunner from :
http://www.sonarqube.org/downloads/

2.Installation : Extract the .zip/.tar in your preferred location.In my case -
sonarQube is extracted at :
/opt/sonarqube-5.0.1
sonarRunner is extracted at :
/opt/sonar-runner-2.4

3.Configure settings for sonarqube's database : Edit the sonar.properties to configure sonarQube's database. Execute the below command from terminal to access the sonar.properties :
 gedit /opt/sonarqube-5.0.1/conf/sonar.properties
then uncomment the following code (for mysql users) by removing # :
#sonar.jdbc.username=sonar -->Line 1
#sonar.jdbc.password=sonar -->Line 2

#----- MySQL 5.x
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?   useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance 

4.Create database : create database for sonarqube with name sonar
create database sonar;
then create a new user :
create user 'provide-username that must be same as in Line 1 in previous step'@'localhost' identified by 'provide-password that must be same as in Line 2 in previous step';
here user has no permissions to do anything with the database until have the access.So provide the full permission on the sonar database
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'%' WITH GRANT OPTION;
Here sonar.* is the access to sonar database and 'sonar' is the username in my case

5.Start sonarQube server : Now start sonarqube server using following command :
/opt/sonarqube-5.0.1/bin/OS-ARCHITECTURE/sonar.sh start
OS-ARCHITECTURE : OS you are using i.e in my case it is linux-x86-64..

6.Configuring sonar-runner : Edit sonar-runner.properties to connect to database(mysql in my case)
execute the command to open sonar-runner.properties :
gedit /opt/sonar-runner-2.4/conf/sonar-runner.properties
then uncomment the following line by removing #
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 

7.Configure grails-project : create sonar-project.properties at the root of your project
in my case it is ABC(project name) so it will be
/home/hitesh/ABC/sonar-project.properties 
and add the following configurations:
	sonar.projectKey=my-project-name
	sonar.projectName=Work
	sonar.projectVersion=1.0
	sonar.sources=grails-app
	sonar.language=grvy
	sonar.sourceEncoding=UTF-8

8.Final Step : Now start analyzing your project by running following command from the root of your project
here is my project directory :
cd /home/hitesh/ABC
then start the sonar-runner here by executing the command :
 /opt/sonar-runner-2.4/bin/sonar-runner
and then analyze your project by hitting the url :
http://localhost:9000

NOTE:FOR GIT USERS,MAKE SURE THAT THERE SHOULD BE NO CONFLICT BEFORE EXECUTING SONAR-RUNNER OTHERWISE IT WILL THROW EXCEPTION SOMETHING LIKE
 Caused by: Unable to blame file grails-app/conf/DataSource.groovy. No blame info at line 33. Is file commited? 

THANKS FOR YOUR TIME

About Author

Author Image
Hitesh Arora

Hitesh is a bright engineer with experience in Core Java , Grails , Elastic Search , Angular JS .

Request for Proposal

Name is required

Comment is required

Sending message..