What you will need to get the ANT svn task to work is:

JDK 1.5/1.6 – You can get that here.
ANT – You can get that here.
SVN client – You can get that here. You will need to register for this.
SvnAnt zip file – You can get that here.

Here is what to do:

Install JDK if you haven’t done so already.
Install ANT (simply unzip the ANT zip file into an appropriate place) if you haven’t done so already.
Install SVN Client.
Install SvnAnt (simply unzip the SvnAnt zip file into an appropriate place).

To use the ANT svn task:

build.properties:
# -----------------------------------------------------------------------------
# build.properties
# This file is referenced by the sample build.xml file.
# -----------------------------------------------------------------------------

svnant.version=1.0.0

# —————————————————————————–
# all jar needed
# —————————————————————————–
lib.dir=C:/svnant-1.0.0/lib
svnant.jar=${lib.dir}/svnant.jar
svnClientAdapter.jar=${lib.dir}/svnClientAdapter.jar
svnjavahl.jar=${lib.dir}/svnjavahl.jar

svnant.latest.url=http://subclipse.tigris.org/svn/subclipse/trunk/svnant/
svnant.this.url=http://subclipse.tigris.org/svn/subclipse/tags/svnant/${svnant.version}/

svnant.repository.user=user1
svnant.repository.passwd=”passwordUser1″

build.xml:
<?xml version="1.0"?>

<project name="Update" basedir="." default="update">
 
  <!--  all properties are in build.properties -->
  <property file="build.properties" />
  <path id="project.classpath">
    <pathelement location="${svnjavahl.jar}" />
    <pathelement location="${svnant.jar}" />
    <pathelement location="${svnClientAdapter.jar}" />
  </path>
  <property name="project.svn.url" value="SVN_URL_HERE" />
 
  <taskdef resource="svntask.properties" classpathref="project.classpath"/>
 
  <target name="update">
    <svn>
      <checkout url="${project.svn.url}" revision="HEAD" destPath="." />
    </svn>
  </target>

</project>

You can get detailed documentation on svn ANT task here.

7 Responses to “svnant – Using SVN with ANT”

  • Narayanan:

    Hi,

    Nice to read your blog. i am trying to use svn with ant.

    followed your points, and got this error.

    update:
    [echo] Exporting application files from svn repository:

    BUILD FAILED
    C:\Util\autobuild\build.xml:28: Cannot use javahl nor command line svn client

    Can you please help me.

    Thanks in advance.

    ———————————–


    ———————————–

    Regards
    Narayanan

  • Two possibilities…
    1. Either your javahl jars are not in classpath
    2. SVN client is not installed

    Here are the options you can try …

    1. dump all your snvant jars in ANT_HOME/lib so that ant can pick them up.
    2. check if SVN client is in path…means make sure you are able to run svn from command line in any directory.

    Hope this will help.

  • Payel Khandelwal:

    hi
    I want to export selected set of files from svn.
    could you please help me..

  • Ramu N:

    I am getting following error.

    BUILD FAILED
    D:\Ethernet-MDT\SVN_TEST\build.xml:30: java.lang.NoClassDefFoundError: org/tigris/subversion/javahl/SVNClientInterface

    Total time: 481 milliseconds

  • Ajit:

    @Priya: Thanks for your post.

    @Narayanan: Make sure that the you have downloaded the correct version of svnant from this link: http://subclipse.tigris.org/svnant.html

  • amit patel:

    if you use svnkit.jar neither client nor javahl jar is required
    svnkit is all java implementation

    use <svn svnkit="true" …

  • grela:

    Hi,

    I am trying to use SVN with ANT and I have dowloaded SVN and SVNAnt.

    However when i type SVN in a command prompt it is not recognised.

    Any advise?

Leave a Reply

*


five − 2 =