A couple days ago I had my first experience with Apache Ant. If you have never heard of it before you should definitely check it out. Apache Ant is a very simple JAVA-based build tool with xml-based configuration files for automation.
I wanted to automate the process of importing/exporting specific MySQL database tables.In the next step I wanted to update and commit the data to SVN. After a quick research I found the JAVA lib svntask which is based on SVNKit very useful.
The only disadvantage in my opinion is that there is almost no documentation yet. To help other developers to get off on the right foot and save some time I’ll give some examples in the following section.
SVN update example:
<!-- SVN update --> <target name="svn-update"> <svn> <update path="/workspace/path" force="false" recursive="false" /> </svn> </target>
Optional arguments you can use are recursive(default: true) and force(default: true).
SVN add example:
<!-- SVN add --> <target name="svn-add"> <svn> <add path="/workspace/project" force="false" /> </svn> </target>
Optional boolean arguments are force, mkdir, climbUnversionedParents, includeIgnored and makeParents(default for all except mkrdir is true).
SVN commit example:
With version 1.0.7 authentication failed for me. So I added the username/password authentication to the commit class. You can get the temporary version here until the next update of svntask.
<!-- SVN Commit -->
<target name="svn-commit">
<!-- don't store password in property files, use input -->
<input
message="Enter SVN password:"
addproperty="svn.password"
/>
<svn>
<commit
path="/workspace/project/trunk"
commitMessage="Test commit"
force="true"
username="user" password="${svn.password}"
/>
</svn>
</target>
Optional boolean arguments are keepLocks and force.
SVN ls update example:
<!-- SVN ls --> <target name="svn-ls"> <svn> <ls repository="http://domain.tld" path="/svn/repos/project/trunk" /> </svn> </target>
Optional argument is delimeter(default: , ).
SVN info example:
<!-- SVN info -->
<target name="svn-info">
<svn>
<info
path="/workspace/project/trunk"
committedRevisionProperty="revisionVersion"
authorProperty="revisionAuthor"
committedDateProperty="revisionDate"
/>
</svn>
<!-- show revision, author and date -->
<property
name="version"
value="At revision ${revisionVersion} by ${revisionAuthor} on ${revisionDate}"
/>
<echo message="${version}"/>
</target>
I didn’t use log, status and switch so far. I will post examples if I will use it in the future.
Some useful links:
svntask: http://code.google.com/p/svntask/
Apache Ant project: http://ant.apache.org/
4 Comments on “svntask examples for Apache Ant”
You can track this conversation through its atom feed.



Nice work!
You’re right, there is almost no svntask documentation.
Would you be willing to tell me how to install svntask ?
Thanks …John
Posted on 24/08/2009 um 11:50 PM.
To install it, just drop svntask.jar and svnkit.jar into the lib folder of your ant installation.
Then put this near the top of your build.xml file:
Posted on 29/09/2009 um 12:39 PM.
Erm, put what near the top of the build.xml file ??
Thanks,
Stephen
Posted on 01/03/2010 um 6:12 PM.
Hi
This is really great help from you.
I am facing an issue what I need to do is check whether a(or multiple) file(s) if it is version-ed or not and if not then perform SVN add else perform SVN commit using SVNANT.
Thanks in advance.
Posted on 17/06/2010 um 12:57 PM.