svntask examples for Apache Ant

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/

11 Comments

  1. Nice work!

    You’re right, there is almost no svntask documentation.

    Would you be willing to tell me how to install svntask ?

    Thanks …John

    Reply
  2. 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:

    Reply
  3. 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.

    Reply
  4. Part of the instructions are missing. Since I’ve put both svnkit.jar and svntask.jar into the ANT_HOME/lib directory and then run the “svn-update” target.

    build.xml files on the line for , so something needs to define that. Document it here please. I suspect it is the missing part of Chris’s response.

    Reply
  5. Is it possible to enter username and password for update?
    I get

    svn: Authentication required for ' Subversion realm'

    any solutions or suggestions to this?

    thanks,
    Michael

    Reply
  6. Below is one sample to get the latest header information..it is assumed the svnkit.jar and svntask.jar are dropped in lib folder of ant

    Reply
  7. hi .. how to get an un merged data as a daily report ?
    example : developers working on 50 files in branch but they merged only 20 files in svn trunk but remaining 30 files forgot to merged . Now is it possible to get that unmerged 30 files data as a daily report automatically ? please can anyone help me ..

    Reply
  8. How to do a simple URL->URL copy??

    I’ve been looking in the javadoc and this tool doesn’t seems to have it implemented :(

    Reply

Leave a Comment.