Adding a custom Ant task to your build toolkit

When I realized the other day that I was going to need to create a new custom Ant task, I was excited by the potential blog post fodder. Surely it was going to be frustrating and complex, and surely my vast sea of followers would benefit from hearing about my trials, tribulations, and eventual triumph. While coding a new service plugin for the RTC server is easy enough, actually getting the server to pick up and run my new code has at times been a less than straightforward process. I imagined updating the build system toolkit would be a similar challenge.

As it turns out, creating the task and updating the toolkit was ridiculously easy, to the point that I was thinking I wouldn’t even bother writing about it. But, since I didn’t see an example out there that walks me through the steps end to end of creating my task and updating the toolkit, I might as well put it out there and potentially save somebody from some unnecessary fear and trepidation. So here we go.

In my case, I needed to write a custom task that generates a list of changed files to be loaded out to MVS. Here are the steps I followed:

0. Follow the steps in the Extensions Workshop on to set up your development environment.

1. Create a new plug-in project to contain the custom Ant task. I cheated and copy-pasted one of the existing plug-in projects in the toolkit, then deleted all the contents and replaced it with my own.

2. Add the build-ant.jar file from plugin to the new plug-in project, and add it to the Classpath from the Runtime tab of the Plug-in Manifest Editor.

3. Create a new Java class that extends If your task does not need to interact with the build data model, you could just extend instead.

4. Override the doExecute() method in your new task, and add setters for any attributes you need to pass in to your task. For example, if you are going to pass buildDefinitionUUID in from your Ant script, you’ll need a public void setBuildDefinitionUUID(String uuid) method in your task.

5. Once your task is coded, export your plugin project using File->Export->Deployable plug-ins and fragments. Specify a destination directory, choose “Package plug-ins as individual JAR archives” and “Allow for binary cycles in target platform,” and use qualifier replacement if you used “.qualifier” in your plugin version.

6. FTP the exported jar file to the build machine, and place it directly in the toolkit directory (e.g., /usr/lpp/jazz/v3.0/buildsystem/buildtoolkit). There is no need to stop and re-start the build agent. Whoa!!

7. To use your new task, add a taskdef to your Ant script, such as:

<taskdef name="loaddeltafiles" classname="net.jazz.ant.samples.tasks.LoadDeltaFiles"/>.

Finally, use the new task somewhere in the script, e.g.:

<loaddeltafiles deleteMetadata="true" generateListing="true" deltaPolicy="FULL" passwordFile="${passwordFile}" prefix="${teamz.scm.dataset.prefix}" repositoryAddress="${repositoryAddress}" userId="${userId}" workspaceUUID="${teamz.scm.workspaceUUID}" buildResultUUID="${buildResultUUID}" />

8. Marvel at your working task and the simplicity of the process.

This entry was posted in Rational Team Concert. Bookmark the permalink.

5 Responses to Adding a custom Ant task to your build toolkit

  1. Ralph says:


    thanks for sharing, this will help me a lot!


  2. Pingback: Sample custom Ant task | ymmv

  3. Pingback: What API’s are Available for RTC and What Can You Extend? | rsjazz

  4. Pingback: Automatically link rebuilt impacted files to a work item – Custom Ant Task | Jorge Díaz's Blog

  5. Pingback: Build Artifacts Publishing and Automated Build Output Management Using the Plain Java Client Libraries | rsjazz

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s