Use of continuous integration tool sonar (II.) [Ant+sonar]

Source: Internet
Author: User

In the previous article we talked about the combination of sonar and MAVEN to achieve code quality review, but because MAVEN's learning cost is high, not any project is suitable, so this article we describe how to use the combination of sonar and ant for Code quality review.

For now, the integration of sonar and ant is not as good as the integration of sonar and MAVEN, so you'll need to write more scripts during use. Let's introduce the steps to use:
1, download sonar and extract to any directory, note that the directory is not allowed to have Chinese;
2, click Bin\windows-x86-32\startsonar.bat Start sonar;
3, download an ant plug-in: Sonar-ant-task-1.1.jar, and stored to a path, the ant script needs to access this file.
4, write an ant script, as follows:

<?xml version= "1.0" encoding= "UTF-8"?>

<project name= "framework-client" default= "Sonar" basedir= "." >

<property name= "Project.name" value= "Framework-client"/>
<property name= "Src.dir" value= "${basedir}/src/main/java"/>
<property name= "Lib.dir" value= "${basedir}/lib"/>

<!--out-of-the-box Those parameters are optional-->
<!--EXAMPLE for MYSQL
<property name= "Sonar.jdbc.url"
Value= "Jdbc:mysql://localhost:3306/sonar?useunicode=true&amp;characterencoding=utf8"/>
<property name= "Sonar.jdbc.driverClassName" value= "Com.mysql.jdbc.Driver"/>
<property name= "Sonar.jdbc.username" value= "Sonar"/>
<property name= "Sonar.jdbc.password" value= "Sonar"/>
-->

<!--SERVER on A REMOTE HOST-->
<!--
<property key= "Sonar.host.url" value= "http://myserver:1234"/>
-->

<!--Define The Sonar task if this hasn ' t been do in a common script-->
<taskdef uri= "antlib:org.sonar.ant" resource= "Org/sonar/ant/antlib.xml" >
<classpath>
<pathelement location= "${lib.dir}/sonar-ant-task-1.1.jar"/>
</classpath>
</taskdef>

<!--Add the target-->
<target name= "Sonar" >
<!--list of Mandatories Sonar properties-->
<property name= "sonar.sources" value= "${src.dir}"/>
<property name= "Sonar.projectkey" value= "Org.example:${project.name}"/>

     <!--list of optional Sonar properties;
    <!--
 & nbsp;   <property key= "Sonar.projectname" value= "This value overrides the name defined in Ant root node"/> ;
     <property key= "sonar.binaries" value= "List of directories which contain for example the J Ava bytecode "/>
     <property key=" sonar.tests "value=" List of test source directories SE parated by a comma "/>
     <property key=" sonar.libraries "value=" List of paths to Librarie s separated by a comma (this libraries are for example used by the Sonar Findbugs plugin) "/>
    -
    
     <sonar:sonar key= "${sonar.projectkey}" version= "0.9" Xmlns:sonar= "Antlib:org.sonar.ant"/>

    </target>
</project>

  5, running the ant script, and after you see the prompts for build successfully, You can access: Http://localhost:9000/to view the results of the code quality Review.

These are the simplest steps to use sonar and ant, with sonar embedded database Derby and standalone application server, and of course support for other databases, such as MySQL, Just modify the sonar.properties configuration file and configure the way to connect to the database in your ant script. In addition, you can use Tomcat, JBoss and other application servers to publish sonar applications, as long as the run sonar a script: Build-war.bat on it, no longer detailed here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.