The Power of Ant (Build System)
By Angsuman Chakraborty, Gaea News NetworkWednesday, 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.):
- 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.
- The test sources can be compiled with a separate target which keeps the compiled classes in separate directory.
- Automatic static analysis to discover defects in the source code, report is in html for easy viewing.
- Javadoc with cross-refernce to source code and JDK classes are linked to JDK documentation on our local server.
- Source code quality analysis and report in html format.
- The run target allows you to run any class from command line with optional arguments (from command line).
- The libraries are grouped in several categories so only the minimal set of required libraries are used for each task
- Spike classes can be run separately
- The test task runs all the available sanity tests. You can specify any groups or exclude any groups of test to run.
- Many tasks like static analysis, javadoc creation or quality analysis are dependent on successful running of the sanity tests
- 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.
- All source code (including test code) and spike solutions are automatically added before checkin.
- 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.
- 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.
- Capturing the subversion version number for incorporating in jar file
- ‘all’ task which completes all common tasks
- 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.
Tags: Ant, Build System, eclipse, Subversion
August 28, 2008: 11:51 pm
@Anjan @Ravindra |
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, |
Angsuman Chakraborty