Skip to content


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>

Posted in A Day In The Life Of, Ant, ColdFusion, Culture, Java, Languages, Tips, Hacks, & Tricks, Tools.

5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Hey Brandon,

    Thanks for posting this - saved me a bundle of time figuring it out myself this morning. I just googled “subversion ant,” and you were #3 with exactly what I needed to do.

    -Joe

  2. Hey Joe,

    It wasn’t uber difficult or anything, but a timesaver that I figured someone else would find useful– glad it helped you out!

    I’ve been taking a look at Model-Glue lately and find it to to be fairly intriguing. Lately I’ve been writing a lot of back-end (only a management GUI) apps which didn’t really work well in an event based architecture like Mach-II. I ended up rolling my own very lightweight architecture which is mostly pure OO and it’s very similar to Model-Glue (like using Config Beans for example).

    Anyhow, I can see myself starting to move to it with the stuff I’m working on as Model-Glue is an open standard rather than my own concoction… nice work!

  3. Mahesh said

    I Have followed the same steps above mentioned
    i.e., have installed the CLI SVN, restarted the machine and when i tried to run the build file by updating as specified above the task is not performed simply it is coming out with out any failure and even not doing a checkout.

  4. You should add failonerror=”true” to your exec line to abort the build if SVN fails.

Continuing the Discussion

  1. devnulled: A blog by Brandon Harper » Adding The Subversion Build Number To Your Application Using Ant linked to this post on August 2, 2005

    [...] grabs the build number from the builds directory where I’ve already deployed a build using a previous task I wrote. 2. The output of said task is pip [...]

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.