craigaspinall.com

15 Nov 2010 - Click. Click. Build.

These days, the first thing I do whenever I start a new project is figure out how to build it. It’s a lesson I learned from Ship It! by the Pragmatic Programmers and a habit that I have gotten into.

I’m not talking about clicking the “build” button in the IDE either. I’m talking about a build that can be run independently on any machine, preferably with a single checkout from the version control system then a single command. If you can do that, then setting up new development machines and/or continuous integration builds is a cinch!

Sounds great, but how do you do it? I’ve only really got experience of doing it with Java projects, although they included a lot of JNI code and I was able to include that too.

First up, you need to decide on a build tool. It could be as simple as a batch file but my current tool of choice is Maven. I’ve also used Ant in the past and I’m looking at Gradle for future builds. The reason I switched to Maven was for it’s dependency handling and reporting, and now it’s well integrated into the popular Java IDEs, meaning your developers can choose their favourite.

Once you’ve got a build tool, you need to ask yourself what you files do you need to build your project? Obviously the source code and build script will be needed but what about resource files, test environments or any other tools that assist with the build. In the past I’ve taken this to the extreme of checking in a copy of the build tool itself and even the JDK. This meant that the only thing you needed to set up a new developer machine was a copy of Subversion, everything else came from the version control system!

The only exception to this rule were the dependencies that I mentioned. When we were using Ant, our projects had a ‘lib’ folder and the dependencies were checked in with the code. With Maven, we set up our own internal repository and shared the dependencies from there. However if you’re going to do this you need to make sure that your Maven repository is backed up with the same frequency as your source code repository!

Newer Posts

Older Posts

This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright ©Craig Aspinall 2011