1. Main
    1. Welcome
    2. Download
    3. Printable PDF
    4. What’s New
  2. Using Buildr
    1. Getting Started
    2. Projects
    3. Building
    4. Artifacts
    5. Packaging
    6. Testing
    7. Settings/Profiles
    8. More Stuff
    9. Extending Buildr
    10. Recipes
  3. Reference
    1. API
    2. Rake
    3. Antwrap
    4. Troubleshooting
  4. Getting Involved
    1. Contributing
    2. Mailing Lists
    3. Issues/Bugs
  5. Project Status
    1. License
    2. Changelog
    3. Specs
Google Custom Search

Getting Started

  1. Installing Buildr
    1. Linux
    2. OS/X
    3. Windows
    4. JRuby
  2. Conventions
  3. Running Buildr
  4. Help Tasks
  5. More Info

Installing Buildr

The installation instructions are slightly different for each operating system. If you are using Ruby, pick the one that best matches your operating system and target platform.

The current release of Buildr for Ruby does not work with Java 6 and can only be used with Java 1.5 or earlier. Buildr for JRuby works nicely with Java 6, consider using that instead.

Linux

To get started you will need a recent version of Ruby, Ruby Gems and build tools for compiling native libraries (make, gcc and standard headers).

On RedHat/Fedora you can use yum to install Ruby and RubyGems, and then upgrade to the most recent version of RubyGems:

$ sudo yum install ruby rubygems ruby-devel gcc
$ sudo gem update --system

On Ubuntu you have to install several packages:

$ sudo apt-get install ruby-full ruby1.8-dev libopenssl-ruby build-essential 

The Debian package for rubygems will not allow you to install Buildr, so you need to install RubyGems from source:

$ curl -OL http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
$ tar xzf rubygems-1.0.1.tgz
$ cd rubygems-1.0.1
$ sudo ruby setup.rb
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Before installing Buildr, please set the JAVA_HOME environment variable to point to your JDK distribution. Next, use Ruby Gem to install Buildr:

$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr

To upgrade to a new version or install a specific version:

$ sudo env JAVA_HOME=$JAVA_HOME gem update buildr
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.0

You can also use this script to install Buildr on Linux. This script will install Buildr or if already installed, upgrade to a more recent version. It will also install Ruby 1.8.6 if not already installed (using yum or apt-get) and upgrage RubyGems to 1.0.1.

OS/X

OS/X 10.5 (Leopard) comes with a recent version of Ruby 1.8.6. OS/X 10.4 (Tiger) includes an older version of Ruby, we recommend you first install Ruby 1.8.6 using MacPorts (sudo port install ruby rb-rubygems), Fink or the Ruby One-Click Installer for OS/X.

We recommend you first upgrade to the latest version of Ruby gems:

$ sudo gem update --system

Before installing Buildr, please set the JAVA_HOME environment variable to point to your JDK distribution:

$ export JAVA_HOME=/Library/Java/Home

To install Buildr:

$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr

To upgrade to a new version or install a specific version:

$ sudo env JAVA_HOME=$JAVA_HOME gem update buildr
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.0

You can also use this script to install Buildr on OS/X. This script will install Buildr or if already installed, upgrade to a more recent version. It will also install Ruby 1.8.6 if not already installed (using MacPorts) and upgrage RubyGems to 1.0.1.

Windows

If you don’t already have Ruby installed, now is the time to do it. The easiest way to install Ruby is using the one-click installer.

We recommend you first upgrade to the latest version of Ruby gems:

> gem update --system

Before installing Buildr, please set the JAVA_HOME environment variable to point to your JDK distribution. Next, use Ruby Gem to install Buildr:

> gem install buildr

Buildr uses several libraries that include native extensions. During installation it will ask you to pick a platform for these libraries. By selecting mswin32 it will download and install pre-compiled DLLs for these extensions.

To upgrade to a new version or install a specific version:

> gem update buildr
> gem install buildr -v 1.3.0

JRuby

If you don’t already have JRuby 1.1 or later installed, you can download it from the JRuby site.

After uncompressing JRuby, update your PATH to include both java and jruby executables.

For Linux and OS/X:

$ export PATH=$PATH:[path to JRuby]/bin:$JAVA_HOME/bin
$ gem install buildr

For Windows:

> set PATH=%PATH%;[path to JRuby]/bin;%JAVA_HOME%/bin
> gem install buildr

To upgrade to a new version or install a specific version:

$ sudo gem update buildr
$ sudo gem install buildr -v 1.3.0

You can also use this script to install Buildr on JRuby. This script will install Buildr or if already installed, upgrade to a more recent version. If necessary, it will also install JRuby 1.1 in /opt/jruby and update the PATH variable in ~/.bash_profile or ~/.profile.

Important: Running JRuby and Ruby side by side

Ruby and JRuby maintain separate Gem repositories, and in fact install slightly different versions of the Buildr Gem (same functionality, different dependencies). Installing Buildr for Ruby does not install it for JRuby and vice versa.

If you have JRuby installed but not Ruby, the gem and buildr commands will use JRuby. If you have both JRuby and Ruby installed, follow the instructions below. To find out if you have Ruby installed (some operating systems include it by default), run ruby --version from the command line.

To work exclusively with JRuby, make sure it shows first on the path, for example, by setting PATH=/opt/jruby/bin:$PATH.

You can use JRuby and Ruby side by side, by running scripts with the -S command line argument. For example:

$ # with Ruby
$ ruby -S gem install buildr
$ ruby -S buildr
$ # with JRuby
$ jruby -S gem install buildr
$ jruby -S buildr

Run buildr --version from the command line to find which version of Buildr you are using by default. If you see (JRuby ...), Buildr is running on that version of JRuby.

Conventions

Lines that start with $ are command lines, for example:

$ # Run Buildr
$ buildr

Lines that start with => show output from the console or the result of a method, for example:

puts 'Hello world'
=> "Hello world"

And as you guessed, everything else is Buildfile Ruby or Java code. You can figure out which language is which.

Running Buildr

You need a Buildfile, a build script that tells Buildr all about the projects it’s building, what they contain, what to produce, and so on. The Buildfile resides in the root directory of your project. We’ll talk more about it in the next chapter. If you don’t already have one, ask Buildr to create it:

$ buildr

You’ll notice that Buildr creates a file called buildfile. It’s case sensitive, but Buildr will look for either buildfile or Buildfile. You can also use Rakefile or rakefile for compatibility with previous versions of Buildr.

You use Buildr by running the buildr command:

$ buildr [options] [tasks] [name=value]

There are several options you can use, for a full list of options type:

$ buildr --help
Option Usage
-f/--buildfile [file] Specify the buildfile.
-e/--environment [name] Environment name (e.g. development, test, production).
-h/--help Display this help message.
-n/--nosearch Do not search parent directories for the buildfile.
-q/--quiet Do not log messages to standard output.
-r/--require [file] Require MODULE before executing buildfile.
-t/--trace Turn on invoke/execute tracing, enable full backtrace.
-v/--version Display the program version.

You can tell Buildr to run specific tasks and the order to run them. For example:

# Clean and rebuild
buildr clean build
# Package and install
buildr install

If you don’t specify a task, Buildr will run the build task, compiling source code and running test cases. Running a task may run other tasks as well, for example, running the install task will also run package.

There are several environment variables that let you control how Buildr works, for example, to skip test cases during a build, or specify options for the JVM. Depending on the variable, you may want to set it once in your environment, or set a different value each time you run Buildr.

For example:

$ export JAVA_OPTS='-Xms1g -Xmx1g'
$ buildr TEST=no

Help Tasks

Buildr includes a number of informative tasks. Currently that number stands at two, but we’ll be adding more tasks in future releases. These tasks report information from the Buildfile, so you need one to run them. For more general help (version number, command line arguments, etc) use buildr --help.

To start with, type:

$ buildr help

You can list the name and description of all your projects using the help:projects task. For example:

$ buildr help:projects
killer-app                 # Code. Build. ??? Profit!
killer-app:teh-api         # Abstract classes and interfaces
killer-app:teh-impl        # All those implementation details
killer-app:la-web          # What our users see

You are, of course, describing your projects for the sake of those who will maintain your code, right? To describe a project, or a task, call the desc method before the project or task definition.

So next let’s talk about projects.

More Info

API The Buildr API documentation.

Rake Buildr is based on Rake, a Ruby build system that handles tasks and dependencies. Check out the Rake documentation for more information.

AntWrap Buildr uses AntWrap, for configuring and running Ant tasks. You can learn more from the Antwrap documentation.

YAML Buildr uses YAML for its profiles. You can learn more about YAML here, and use this handy YAML quick reference.