A Few Ant Gotchas Using External Property Files (on Windows)

After watching John Paul Ashenfelter's Pragmatic ColdFusion: Build, Test, Deploy preso I decided to try hacking up one of my Ant build scripts to use an external property file. It seemed like this would be a bit more flexible.

I initially just copied all my property statements from my build.xml's "init" target to my external property file. And things ran up to a point and then I ran into

In my build.xml

CODE:
  1. <property name="project.build.src" value="D:\build\${project.name}"/>

In my common.properties file (note double slashes)

CODE:
  1. project.build.src = D:\\build\\${project.name}

Or you could do (note forward slashs)

CODE:
  1. project.build.src = D:/build/${project.name}

Also references to UNC paths changed:

In build.xml

CODE:
  1. <property name="project.build.dev"2 value="\\myserver\${project.name}$" />

In common.properties (note forward slashs)

CODE:
  1. project.build.dev = //myserver/${project.name}$

I've got a few properties still buried in my script that are dependent on certain targets but I think with a bit of tweaking I can reference those externally as well. Then ideally any developer on our team can simply tweak the external file without messing with the more complicated build.xml.

This article contains a few more good tips: Flexible User and Environment Ant Configuration which I'm going to implement as well.

One Comment

  1. Posted December 30, 2007 at 5:30 pm | Permalink

    MUCH more flexible, IMO. Having used properties files for a year or so, I’ve refined them to such a degree that I have “base” properties and build files which can be refined on a project-by-project basis. Once the project build file is complete, only the properties file needs to be modified in order to build/deploy that project to multiple servers (dev, staging, prod, etc.). Works beautifully.

    Properties files are easy to modify, script files…less so, I think. :-)

Creative Commons License

Copyright © 2007 thecrumb.com. All rights reserved.