buildr-gemjar

buildr-gemjar is an extension for buildr that makes it easy to package gems and their dependencies into a jar so that JRuby can detect them on the classpath.

Installing

buildr-gemjar is distributed as a rubygem on rubygems.org. Install it as you would any other gem:

$ gem install buildr-gemjar

Using

buildr-gemjar provides a package type called :gemjar. Sample use:

# buildfile
require 'buildr-gemjar'

define 'sinatra-gems' do
  project.version = '1.1.2'

  package(:gemjar).with_gem('sinatra', project.version)
end

When you run buildr package, the result will be a JAR which contains sinatra 1.1.2 and all its dependencies.

You can specify multiple gems:

package(:gemjar).
  with_gem('activesupport', '2.3.10').
  with_gem('facets, '2.4.5')

You can specify additional sources on top of rubygems.org:

package(:gemjar).
  add_source('http://myrepo.local/gems').
  with_gem('my-orm', '1.0.3')

You can also include a gem for which you have a .gem package:

package(:gemjar).with_gem(:file => _('snapshot-gem-2.0.7.pre.gem'))

Caveats

It's important that the name of your JAR not be the same as anything you will require from it. E.g., in the sample above, if the JAR were named sinatra.jar, it would not be possible to require "sinatra" from it. (This is a general JRuby requirement, not something that's specific to this tool.)

Compatibility

buildr-gemjar has been tested with buildr 1.4.4 on ruby 1.8.7, 1.9.2, and JRuby* 1.5.6. It's expected that it will work with any fairly recent version of buildr. It's been tested on OS X and Linux; it may or may not work on Windows.

(*The spec suite does not execute on JRuby for no reason I've yet been able to track down, but manual testing indicates that the extension works fine on that platform.)

Future work

  • Remember requested gems so that rebuilds can automatically happen on configuration changes. (Workaround: build clean.)
  • Use bundler to get a coherent list of dependencies across several gems. (It would already do this, except that bundler doesn't support sourcing a gem from a .gem file, which is a more important feature.)
  • Improve performance. Currently a new JVM is spun up to do each gem install, which can be slow if there are a lot of gems. However, the install process needs to change the environment for rubygems so I'm not sure this can be avoided.
  • Support Windows.

Contact

For bugs and feature requests, please use the github issue tracker. For other questions, please use the buildr users mailing list or e-mail me directly.

About

Copyright 2011, Rhett Sutphin.

buildr-gemjar was built at NUBIC.