How to macro-ify ant targets?

Posted by Jonas Byström on Stack Overflow See other posts from Stack Overflow or by Jonas Byström
Published on 2010-03-22T11:40:07Z Indexed on 2010/03/22 11:41 UTC
Read the original article Hit count: 308

Filed under:

I want to be able to have different targets doing nearly the same thing, as so:

ant build   <- this would be a normal (default) build
ant safari  <- building the safari target.

The targets look like this:

<target name="build" depends="javac" description="GWT compile to JavaScript">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
    <classpath>
      <pathelement location="src"/>
      <path refid="project.class.path"/>
    </classpath>
    <jvmarg value="-Xmx256M"/>
    <arg value="${lhs.target}"/>
  </java>
</target>

<target name="safari" depends="javac" description="GWT compile to Safari/JavaScript">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
    <classpath>
      <pathelement location="src"/>
      <path refid="project.class.path"/>
    </classpath>
    <jvmarg value="-Xmx256M"/>
    <arg value="${lhs.safari.target}"/>
  </java>
</target>

(Nevermind the first thought that strikes: throw out ant! That's not an option just yet.) I tried using macrodef, but got a strange error message (even though the message didn't imply it, it think it had to do with putting a target in sequential). I don't want to do ant -Dwhatever=nevermind. Any ideas?

© Stack Overflow or respective owner

Related posts about ant