Buildr – The build system that doesn’t suck

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”:http://ant.apache.org/ and “all-in-one” solutions like “Maven”:http://maven.apache.org/. Both are based on huge “XML”:http://xml.iscrapbecause.it/ 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”:http://lmgtfy.com/?q=maven+sucks 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!

h2. scripting builds

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”:http://www.gradle.org/, “GMaven”:http://docs.codehaus.org/display/GMAVEN/Home, “Sbt”:http://code.google.com/p/simple-build-tool/, “Raven”:http://raven.rubyforge.org/, “Gant”:http://gant.codehaus.org/ or “Antwrap”:http://antwrap.rubyforge.org/ as examples.
About one year ago I stumbled over another build tool that claims the slogan “The build system that doesn’t suck”:http://buildr.apache.org/ which I found quite promising!

h2. dynamic builds with Buildr

Buildr is an expressive Ruby DSL for managing builds based on “Rake”:http://rake.rubyforge.org/ and Ant. Defining a Java project that follows “the default Apache directory structure”:http://buildr.apache.org/projects.html#dir_structure is dead simple:

# 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”:http://buildr.apache.org/buildr.pdf. There are some sophisticated “examples of how to use Buildr”:http://github.com/phoet/buildr-examples hosted on github as well.

Build, don’t goof up XML!

7 thoughts on “Buildr – The build system that doesn’t suck

  1. Dani

    So, to avoild learning maven, I have to install ruby, learn ruby, install rubygems and learn about gems, etc.. And all this just to get a small percentage of what maven can do? Wouldn’t it be faster to just learn maven directly?
    Don’t take me wrong, I don’t like maven either because its complexity, but I don’t think your approach is much better.

  2. admin Post author

    The essence of the article is that I like to use a scripting language for my builds. It is not about wheather or not I like maven.

  3. James Lorenzen

    I think maven 3.0 supports other types of languages besides XML to create a build file. I know groovy is one of them and I believe there are a few other languages it supports.

    If I were starting a new java project today I would way heavily maven 3 and buildr.

  4. Real life

    This post reminds me of related posts of type “Look how easy it is to write a HelloWorld-application with this shiny framework X!”

  5. Pingback: Creating a Maven webapp from scratch | #nofail

Comments are closed.