Using Ant to execute CVS commands
Ant has several tasks which allow CVS commands to be included within the
build.xml file. Incidentally, similar commands are available for other source
management systems, so even if you use a package other than CVS, you can take
advantage of this. Where this is especially useful is for meta-building, for
example a build.xml file which does integration building by checking out and
building a fresh copy of the project from the repository. In practice CVS
checkout is rather slow, so it's usually better to use an HTTP or FTP task
to fetch an archive with the source code than to use CVS. Additionally,
committing changed source code files using a scripted process such as Ant
is generally a bad idea, since it may add changes you didn't intend, and
doesn't properly log comments about the changes.
Good practices
There are a number of good team development practices which you should keep
in mind when using Ant and CVS in this way. One is to avoid hoarding code -
you should check code into the repository continually rather than waiting
until a release is imminent. Teams or developers new to this process often
delay checking in changes because it seems like too much hassle to continually
fiddle with the code to resolve small conflicts with other developers' code.
But if you cultivate the habit of checking in, updating, and building all of
your code frequently, it becomes second nature, and is well worth avoiding
the pain of integrating code which has been developed separately over weeks
or months.
The flip side of this rule is not to check in broken code. Anyone checking
out a fresh copy of the latest code from CVS should be able to build and
run the project without errors. Try to develop your code in small chunks.
Every time you change or add a bit of functionality, update all of the code
for the project from the repository to merge other developers' changes,
fully test the code by running automated tests, then check in your changes.
The smaller the chunk of code you check in, the simpler it is to integrate
it into the build, and the smaller the impact will be on other developers.
Unit testing is standard practice these days, and Ant makes running tests
with Junit, HTTPUnit, and similar packages a snap. Again, cultivate the
habit of writing and running test code along with your main code and your
life will be much easier in the long run.
Conclusion
The practices recommended here were taken from Java projects at the Apache
Jakarta project, so you might consider taking a look at their source code,
and even following development of interesting projects there, to glean more
tips on good group development practices.
One thing you will learn is that the Jakarta folks are embarking on the next
level of build management tools. This movement is still new, in fact there are
at least two competing tools being developed for this task,
Maven and
Centipede.
The idea of these tools is to automatically generate the build files for a
project using a project descriptor file. So rather than deciding how to organize
your project files and write your build.xml, these tools will organize and
manage your build files for you. They not only build your code, they also
generate tests, documentation, and can even build your distribution web site.
Hopefully this article has given you some ideas for making the process of
building your projects and managing code easier, as well as supplying
starting points for learning more.
Download:
AntCVSBuild.zip
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.