sonarqube integration with ant for code quality analysis
TRANSCRIPT
SonarQube Integration with ANT build file for Code Quality Analysis
By Ramakrishna Narkedamilli
In this Presentation will see how to integrate Java code with Sonarqube server through ANT build file for the code quality analysis.
Pre-requisites
SonarQube server with required setup and access.
SonarQube ANT task jar file( sonar-ant-task-2.3.jar ) and this can be download from below location
http://downloads.sonarsource.com/plugins/org/codehaus/sonar-plugins/sonar-ant-task/2.3/sonar-ant-task-2.3.jar
Below are the steps to follow Need to add the sonar-ant-task-2.3.jar build path.
Right Click on the ANT build.xml file and select Run As --> External Tool Configuration --> Classpath --> User Entries --> Add External Jars --> Select the sonar-ant-task-2.3.jar from above location --> click on Apply.
Integrating With SonarQube server
Open the build.xml file and add the statement xmlns:sonar="antlib:org.sonar.ant" in the <Project> tag ( This is to run the ant libraries).
Now we need to add the set of Sonar properties to establish the connection with SonarQube server.
Add the below list of sonar properties in the buid.xml target "init" . Modify the values appropriately ( sonar.projectKey, sonar.projectName and sonar.projectVersion )
<property name="sonar.host.url" value=SONAR HOST URL /><property name="sonar.login" value=SONAR USER NAME /><property name="sonar.password" value=SONAR PASSWORD /><property name="sonar.jdbc.url" value="jdbc:oracle:thin:@sonar01.hsa.co.uk/XE" /><property name="sonar.jdbc.driverClassName" value="oracle.jdbc.OracleDriver" /><property name="sonar.jdbc.username" value=SONAR DATABASE USERNAME /><property name="sonar.jdbc.password" value=SONAR DATABASE PASSWORD /><property name="sonar.projectKey" value=SONAR PROJECT KEY /><property name="sonar.projectName" value=SONAR PROJECT NAME /><property name="sonar.projectVersion" value="1.0" /><property name="sonar.language" value="java" /><property name="sonar.sources" value="src" /><property name="sonar.verbose" value="true" /><property name="sonar.sourceEncoding" value="ISO-8859-1" />
Finally, need to add the new target "sonar" in build.xml file <target name="sonar" depends="init"> <taskdef uri="antlib:org.sonar.ant"> </taskdef> <!-- Execute the SonarQube analysis --> <sonar:sonar /> </target>
Save the file. At this point Build.xml is modified properly to integrate with SonarQube server.
Click on Window --> Show View --> Other --> Ant and click Ok in order to select the Ant view.
Click on Ant view --> Add Buildfiles --> Select the build.xml file.
Double click on target sonar. It will run the sonar analysis and upload the results to sonar server.
In the logs you will find a SonarQube server link where the results gets uploaded. Simply copy that and paste in browser to see the analysis report.
You can browse for Code major and critical issues and you will find the relevant suggestions to fix this.
You can fix the issues and run the ANT build again to see the results get updated.
THANKS YOU By Ramakrishna Narkedamilli