Much ado about scripting, Linux & Eclipse: card subject to change


Cleaner Ant Build Logs: Get Rid of "Trying to override old definition of task"

If you use macros in Ant, you have probably seen clutter in your log such as

Trying to override old definition of task ...

Here's how to purge this garbage from your log and keep your build output cleaner.

  1. move your macros into a target such as <target name="init">
  2. have your main target(s) depend on the target that defines the macros
  3. call your macros

You can make your log even quieter with -q when running ant, eg., ant -f build.xml -q

Here's a complete example that will first self-bootstrap itself by downloading Ant-Contrib, define two ant macros, and produce very quiet output (unless debug=true):

<project default="run">
 <property name="COMMON_TOOLS" value="${}" />
 <property name="debug" value="false"/>

 <target name="get.ant-contrib" unless="ant-contrib.jar.exists">
  <property name="ANTCONTRIB_MIRROR" value="" />
  <get usetimestamp="true"
  <touch file="${COMMON_TOOLS}/" />
  <mkdir dir="${}/ant-contrib-1.0b2-bin.zip_" />
  <unzip src="${COMMON_TOOLS}/"
  <copy file="${}/ant-contrib-1.0b2-bin.zip_/ant-contrib/lib/ant-contrib.jar"
  <delete dir="${}/ant-contrib-1.0b2-bin.zip_" includeemptydirs="true" quiet="true" />

 <target name="init">
  <available file="${COMMON_TOOLS}/ant-contrib.jar" type="file" property="ant-contrib.jar.exists" />
  <antcall target="get.ant-contrib" />

  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <pathelement location="${COMMON_TOOLS}/ant-contrib.jar" />
  <macrodef name="debug">
   <text name="echo" />
      <isset property="debug" />
      <istrue value="${debug}" />
      <echo message="@{echo}" />

  <macrodef name="list.count">
   <attribute name="list" default="" />
    <var name="count" value="" />
    <for param="listitem" list="@{list}" delimiter=", ">
      <var name="count" value="${count}0" />
    <length property="list.count.return" string="${count}" />

 <target name="run" depends="init">
  <property name="list" value="foo bar baz"/>
  <list.count list="${list}" />
  <debug>For list [${list}], size = </debug>



Kevin Gorham said...

Nice post. It doesn't fix my particular "Trying to override old definition" problem but it is nice to see someone else has this issue. Also, that's a nice example of macros--something I'm not currently using in ant.