Simple Integration of Ant and Subversion

Last week I decided it was time to start looking at integrating the check-out of code from Subversion as a part of my build process for the various projects I work on. Turns out, it’s pretty easy.

Download the CLI Subversion client and install it. You may need to reboot afterwards (I rebooted my machine in the process of getting this to work, so it’s possible that the path variable changed then.)

Below are a few snips from one of my build.xml files which pull the code out of Subversion using the CLI client. It probably won’t be formatted correctly (something seems to be tripping up the code tag), but I’ll check it out later.


<property name="root.dir" value="${basedir}"/>

<property name="root.src" value="c:\wwwroot"/>
<property name="root.dev" value="c:\wwwroot"/>
<property name="root.buildpath" value="c:\Builds"/>
<property name="root.backuppath" value="c:\Backups\Code" />
<property name="root.testingpath" value="\servername\path"/>

<property name="project.name" value="ThisProject" />
<property name="project.dev.root" value="${root.dev}${project.name}"/>
<property name="project.build.root" value="${root.buildpath}${project.name}"/>
<property name="project.backup.root" value="${root.backup}${project.name}" />
<property name="project.testing.root" value="${root.testing}${project.name}"/>

<property name="svn.rooturl" value="svn://svnurlhere/"/>
<property name="svn.username" value="svnusername"/>
<property name="svn.password" value="svnpassword"/>
<property name="svn.projecturl" value="${svn.rooturl}${project.name}/trunk/"/>
<property name="svn.revision" value="HEAD"/>

<target name="cleanBuild" description="Cleans the build directory">
<delete dir="${project.build.root}" />
</target>

<target name="createBuildDir" description="Creates the build directory">
<mkdir dir="${project.build.root}" />
</target>

<target name="makeBuild" description="Pulls code from Subversion into the build directory" depends="cleanBuild,createBuildDir,checkoutBuild">

</target>

<target name="checkoutBuild" description="Pulls code from Subversion into the build directory">
<exec executable="svn">
<arg line="co ${svn.projecturl} ${project.build.root} -r ${svn.revision} --username ${svn.username} --password ${svn.password}"/>
</exec>
</target>

This entry was posted in Culture, Languages, Tips, Hacks, & Tricks, Tools and tagged , , , , , . Bookmark the permalink.

8 Responses to "Simple Integration of Ant and Subversion"

Leave a reply