The ONJava.com article, Top 15 Ant Best Practices, covers the use of properties for the purpose of introducing configurable settings of a build script. As stated in the article, there are two approaches to defining properties, one being the use of the property element in the build script itself and the second being a properties file that can be included by the script using the file attribute on the property element. Often in build scripts you will find a mixture of the two. For example:
<property file="build.properties"/> <property name="src.dir" location="src"/>
In the example given, the purpose of including the build.properties file before declaring the src.dir property is to allow the properties within the build file to be replaced by properties defined in the build.properties file. This is possible because of an Ant feature whereby a property can only be assigned a value once.
It is possible, as the aforementioned Ant Best Practices article describes, to define all of your properties within a properties file rather than the corresponding build script. It is also possible to have properties defined in either or both locations. In some of the build scripts that I have encountered over time the usage pattern has been to define all static properties, i.e. properties that are not likely to change, within the build script and all properties that are dependant upon a user’s environment within a properties file. However, I would recommend against such an approach. I find that it is important to keep the build process self documenting. I feel that this is best achieved by defining all of the properties that you require in a single location, preferably the build.xml file. This allows you to operate without a separate properties file while enabling users with different environments to customise the build without the need to modify the build script.
One of the areas that this approach encounters problems is in relation to installation paths (for example the installation path of your J2EE container for deployment within the build script). In instances such as this, I believe that it is best to define the path that shall be used by the continuous integration environment within the build script’s property definition. In the event that a user chooses to deviate from the continuous integration conventions they may override the installation location through the use of a build properties file.
To summarise, define all of your build properties in a single location. This may either be in the build script itself or from a referenced build.properties file. To enable users to override default property values, ensure that the build script references a properties file (for example user.properties) that does not exist in the project distribution and encourage them to use this file for setting custom property values.