views:

195

answers:

3

How to specify gem dependencies in a way that user with only ruby, rake and rubygems installed could issue a single rake command to install all the dependencies required? Is it possible to use the same dependency specification when building gem with GemBuildTask?

A: 

I think currently you'd have to write a custom rake task that talked to the Gem library.

It's possible that rip, the (very) new kid on the block, will make it all easier, but it's very early days.

But someone else may have a better way...

Mike Woodhouse
A: 

If your app is packaged as a gem, you could add the dependencies to the gemspec and rubygems will attempt to install them for you when you install the gem.

There are a bunch of ways to make a gem out of some ruby code. Recently I have taken to using jeweler.

With it, you can install a project as a gem by running rake install. There are some instructions on how to do dependencies on its github wiki.

BaroqueBobcat
+3  A: 

It's actually pretty easy to set up a rake task that installs a bunch of gems:

task :install_gems do
  require "rubygems"
  require "rubygems/dependency_installer"

  installer = Gem::DependencyInstaller.new

  [["rack"], ["merb-core", "1.0.12"]].each do |args|
    installer.install(*args)
  end
end

Of course, you could extract this into a method and write a prettier way to specify your dependencies, but this should work great.

Yehuda Katz
I like this - it's a good way to offer to install dependencies for end users as well.
MattK
Of course, we're working on a solution that will be much more robust in Rails 3 that will be available for standalone apps as well :)
Yehuda Katz