Configurable Builds: Overriding properties
Sometimes when configuring our build for flexibility we don’t need to spend the time required to create one build configuration per user or one build configuration per environment.
In these cases we can just override properties when we call Nant from the command line.
One recent example where I made use of this was where we had one configuration file with properties in but wanted to override a couple of them when we ran the continuous integration build.
Since build properties are immutable (i.e. once they are set they can’t be changed) if we set them from the command line the build script makes use of these values.
For example we might have the following in our build file:
<property name="repository.url" value="http://localhost:3000" />
But when we’re running it on cruise control we have the repository on a different machine. We can override it like so:
nant -buildfile:build-file.build target-name -D:repository.url=http://some-remote-url
If we have more than one property we want to override it might be a bit annoying to have to pass them all via the command line. We can define them in a file to overcome this problem:
nant -buildfile:build-file.build target-name @ci.properties.xml
where ci.properties.xml contains the following:
-D:repository.url=http://remote-url:3000
-D:some.other.property=newvalue
If you start seeing a lot of properties in this file then it is probably an indicator that you need to have a more robust solution but this works for providing simple flexibility.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.