The Power of Ant (Build System)

By Angsuman Chakraborty, Gaea News Network
Wednesday, August 27, 2008

I am using Ant (Java based build system) for our project. Ant is an exceptionally powerful build system and should be the only build system you will ever need. You don’t really need code monsters like Maven (or pile of …. as Bileblogger loves to say). With little effort here’s what I achieved in few hours (aside from the obvious capability of compiling, running, building jar files etc.):

  1. Our test sources (Java) are located in the same directory as the regular Java source files. However during compiation of the source code we exclude the Test sources.
  2. The test sources can be compiled with a separate target which keeps the compiled classes in separate directory.
  3. Automatic static analysis to discover defects in the source code, report is in html for easy viewing.
  4. Javadoc with cross-refernce to source code and JDK classes are linked to JDK documentation on our local server.
  5. Source code quality analysis and report in html format.
  6. The run target allows you to run any class from command line with optional arguments (from command line).
  7. The libraries are grouped in several categories so only the minimal set of required libraries are used for each task
  8. Spike classes can be run separately
  9. The test task runs all the available sanity tests. You can specify any groups or exclude any groups of test to run.
  10. Many tasks like static analysis, javadoc creation or quality analysis are dependent on successful running of the sanity tests
  11. Before compilation the latest code is checked out from the subversion repository (called update in subversion). This ensures that the developer is always using the latest code base.
  12. All source code (including test code) and spike solutions are automatically added before checkin.
  13. You can checkin code (called commit in subversion) only after successful compilation and completion of sanity tests. This ensures that the checked in code is never broken.
  14. We also generate a jar file for a sub-project by concatenating the source along with all dependent jar files for easy of deployment. It also includes a manifest file which allows the application to be run with a simple java - jar command.
  15. Capturing the subversion version number for incorporating in jar file
  16. ‘all’ task which completes all common tasks
  17. Certain tasks are hidden from common users

While each of them is not hard to do, a nice integration is what gives it real value. A development team can be very productive with a build system which eases its tasks and enforces good habits like running tests before checkin, updating to latest version before compilation etc.

Instead of investing in big hard to understand systems, I prefer to use simple but powerful software like ant to get what I want and with low cost (my time * hourly rate as opposed to software cost + my time to learn * hourly rate + my time to implement + hourly rate + consultants time * hourly rate). Ant can be used from command line (my preference) or from within modern IDE like Eclipse or Netbeans.

Discussion
August 28, 2008: 11:51 pm

@Anjan
Nice to hear from you.
I will release it as part of a framework for rapid Java development. I am gaining more experience with this product (TEN) we are currently developing. After we release TEN I also plan to package the build tool and several utilities we developed for the Java community.

@Ravindra
Why use CruiseControl when you can create a target (which does the build and send notifications on error) and run it from a cron job? I like cruise control but I prefer something simpler.


Ravindra
August 28, 2008: 8:05 am

Yes, ANT is a very powerful system. You can also consider using CruiseControl.NET for continuous integration of your Software Development.

August 27, 2008: 5:35 pm

hi angsuman,

Can you share your ant file ? you can anonymize any secret info BUT still make your script available.

thank you,

BR,
~A

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :