If you are a Java guy like me, you are probably doing a lot of ugly tasks in your everday work. One of these tasks is build management.
The Java community tries to tackle builds with standard tools like Ant and “all-in-one” solutions like Maven. Both are based on huge XML configuration files that are hard to read, painful to maintain and impossible to test. Even though these tools are mainstream, they are quite buggy. Just have a look at all the rants about maven you find on the net.
Java builds are known to become very complex over time. You have to compile things found here, include stuff from there, resolve dependencies in a remote repository, add something to the version control, […even more crazy stuff…]. Addressing such complex and dynamic tasks with static structures is just a stupid idea. What you really want to do is scripting!
Using scripting languages is a natural way to address build tasks. If you are close to the operating system you can do most things easily. Trust your admin, the shell is your friend!
The simplest way to get scripting power is to use bash scripts, which has the drawback that it’s not interoperable and you will always have to show consideration for WINDOW$ users…
There are portable frameworks that try to integrate the flexibilty of scripting languages like Ruby with the power of Ant or Maven. Have a look at Gradle, GMaven, Sbt, Raven, Gant or Antwrap as examples.
About one year ago I stumbled over another build tool that claims the slogan The build system that doesn’t suck which I found quite promising!
dynamic builds with Buildr
# buildfile.rb desc 'define a project called simple' define 'simple' do info 'create a simple.jar from this project' package :jar end
After installing the Buildr Gem you can call built-in or custom Buildr tasks on your project. This is done in the same way Rake would do it:
# install the Buildr gem gem install buildr # check buildr version buildr -V => Buildr 1.3.5 (JRuby 1.4.0) # build your Java project: compile, test, package buildr package
Since Buildr is based on sensible defaults, it knows where to look for your class files, resources and tests. Before creating the jar, it compiles everything, executes the tests and then zips up the bytecode into a distributable.
Buildr does not support every build feature by default, but it’s easy to extend. Buildr at its core is just a bunch of tasks, chained in a predefined order. You can easily write your own tasks and plug them into the build to fit your needs. Buildr provides method hooks that allow you to integrate your tasks into the build cycle.
If this small example makes you say “Awesome!”, you should have a look at the best documentation of an open source framework I have ever seen. There are some sophisticated examples of how to use Buildr hosted on github as well.
Build, don’t goof up XML!