SvnAnt Task/Type Definition Import

I'm finally getting wise and leveraging ANT more, and yesterday was my first attempt at integrating some Subversion tasks. I discovered SvnAnt rather quickly, but didn't have a good sense for the best way to leverage it. Marc Esher kindly helped with a response to my comment here.

Rather than repeating a bunch of path/fileset/typedef lines in every build file that requires SVN tasks, I decided to create a simple build file that would handle this type definition and allow me to place just one import line into each build file that requires SVN tasks.

To start, I downloaded the proper SvnAnt distribution (from here), unzipped the folder under my /opt directory (I'm running Ubuntu), and created a symbolic link to the folder so I can reference it as /opt/svnant.

Then, under my /opt/svnant folder I created a build file called svnant-typedef.xml with the following:

<!--
    This build file serves to map SvnAnt's task and type names to their implementing classes.
    This file should be located in the SvnAnt distribution folder root (parent directory of /lib).
    It can be imported to any build file, rather than repeating, for example:
    <import file="/opt/svnant/svnant-typedef.xml" />
-->

<project name="svnant-typedef" basedir=".">

    <!-- get directory of current build file -->
    <dirname property="svnant.basedir" file="${ant.file.svnant-typedef}" />

    <!-- file set for SVNAnt classpath reference -->
    <path id="svnant.classpath">
        <fileset dir="${svnant.basedir}/lib">
            <include name="*.jar" />
        </fileset>
    </path>

    <!-- task/type definitions for SVNAnt library -->
    <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" />

</project>

You can read about the ANT import task and its special properties here.

Now I need only import the above file in build file's that will use SVN tasks. Here's an example:

<project name="example" default="main" basedir=".">

    <import file="/opt/svnant/svnant-typedef.xml" />

    <target name="main">
        <svn svnkit="true" javahl="false">
            <export srcurl="file:///home/svn/example/trunk" destpath="/tmp/example" />
        </svn>
    </target>

</project>

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden.