How to Integrate Subversion Into Your Ant Build ? – Step by step guide

svn-integration-in-ant-build

SVNAnt
SVNAnt is an Ant task allowing you to interact with Subversion within the convenience of your Ant build script. No more writing custom scripts to get the revision of your repository to tag your release jars. Nor do you have to make command line calls to checkout your latest and greatest as part of your continuous integration process. With SVNAnt, you have the familiarity of the Ant syntax and the flexibility you need for interacting with Subversion.
Features
SVNAnt is a full-featured Subversion client capable of using the native Java bindings or command-line wrappering depending on which is available. Beyond how it works, SVNAnt allows you to do all svn subcommands but the following:

blame cleanup help list
lock log merge propedit
proplist resolved unlocked  

If the svn subcommand is not listed here, you can use it in your Ant build file. Before we continue start using SVNAnt, we have to install it and configure Ant to use it.
Installation
Now that we know what SVNAnt is and what its features are, lets install SVNAnt so that you can begin to use SVNAnt to access Subversion within your Ant build cycle.

Step 1. (Download, Compile and Extract)
This step will download, compile, and “install” the latest version of SVNAnt.
1.1 Using Subversion, checkout the SVNAnt project located here: http://subclipse.tigris.org/svn/subclipse/trunk/svnant
1.2 From the command line, while inside of the location where you checked out SVNAnt to, run “ant makeDistrib”
1.3 Extract the .zip file created in the build directory of your SVNAnt source to a location of your choosing

Step 2. (Modify your build.xml)
The next step is to tell Ant how to find your SVNAnt task by adding the following to your build.xml file:
<path id= “svnant.classpath” >
<fileset dir= “/PATH/TO/YOUR/EXTRACTED/SVNANT-ZIP” >
<include name= “*.jar” />
</fileset>
</path>

<typedef resource=”org/tigris/subversion/svnant/svnantlib.xml” classpathref=”svnant.classpath” />
That should be it. I know that it appears to be too good to be true so lets verify this.

Step 3. (Verify installation)
Building upon Step 2, lets create a new ant task that will use the wcVersion feature of SVNAnt to get some information about your repository from a local working copy:
<target name=”testSVNAnt”>
<svn>
<wcVersion path= “PATH/TO/YOUR/WORKINGCOPY” />
</svn>

<echo message= “Subversion repository url: ${repository.url}” />
</target>
(Note: In the event that you need to pass credentials to Subversion, look here.)
The output should be something similar to this:
$ ant testSVNAnt

Buildfile: build.xml

testSVNAnt:
[svn] <WcVersion> started …
[svn]  finished.
[echo] Subversion repository url: http://svn.apache.org/repos/asf/incubator/openejb/trunk

BUILD SUCCESSFUL
Total time: 43 seconds

Pat yourself on the back. You have successfully installed SVNAnt and you are ready to implement Subversion into your Ant build cycle. Instead of us going through each available feature for SVNAnt, please view the SVNAnt Documentation. Now lets talk about why you may want to use SVNAnt to allow for Subversion interaction inside of your Ant build cycle.

Tagged : / / / / / / / / / / / / / / / /