ANT’s best practices - IV

11 May 2008

In this post, I have discussed how dependency management can make build process faster and more manageable.

Build script should have dependency management to keep thing simple and fast. Complex Java applications comprise of various tiers like a Swing GUI, a web interface, an EJB tier, and shared utility code. You need to clearly define which Java packages belong to which layer of the system. If you don’t do this, then hundreds or thousands of files will be compiled each time you change something, which will slow down the build process. If you clearly define the dependency in your build script, then changing the layout of a GUI panel will not cause you to recompile your servlets and EJBs. This is what we require.

A good practice is to compile large projects in stages. For instance first compile shared utility code and place the results into a JAR file. Then, compile a higher level portion of the project against the JAR file(s) created in the first step. Repeat this process until you reach the highest level of the system. So it’s a like a chain and you go from bottom to up. This approach of building in stages enforces dependency management.

Another good practice is to define and reuse paths. A buildfile makes more sense if paths are defined once in a central location and we can use these paths throughout the buildfile. Its like declaring and defining the variable at the start of the Java class and using them thought the class. Time for an example:

<project name="sample" default="compile" basedir=".">
  <path id="classpath.common">
    <pathelement location="${jdom.jar.withpath}"/>
    ...etc
  </path>
  <path id="classpath.client">
    <pathelement location="${guistuff.jar.withpath}"/>
    <pathelement location="${another.jar.withpath}"/>
    <!-- reuse the common classpath -->
    <path refid="classpath.common"/>
  </path>
  <target name="compile.common" depends="prepare">
    <javac destdir="${dir.build}" srcdir="${dir.src}">
          <classpath refid="classpath.common"/>
          <include name="com/oreilly/common/**"/>
    </javac>
  </target>
</project>

del.icio.us:ANT's best practices - IV  digg:ANT's best practices - IV  spurl:ANT's best practices - IV  wists:ANT's best practices - IV  simpy:ANT's best practices - IV  newsvine:ANT's best practices - IV  blinklist:ANT's best practices - IV  furl:ANT's best practices - IV  reddit:ANT's best practices - IV  fark:ANT's best practices - IV  blogmarks:ANT's best practices - IV  Y!:ANT's best practices - IV  smarking:ANT's best practices - IV  magnolia:ANT's best practices - IV  segnalo:ANT's best practices - IV  gifttagging:ANT's best practices - IV

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: ANT's best practices - IV

Leave a Reply