Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Gemspec Dependency: Is possible have a git branch dependency?

Is possible have a git branch dependency, inside mygem.gemspec?

I'm thinking something similar to the following:

gem.add_runtime_dependency 'oauth2', :git => '[email protected]:lgs/oauth2.git'

... but it doesn't work.

like image 633
Luca G. Soave Avatar asked Jun 27 '11 21:06

Luca G. Soave


3 Answers

This is not possible, and likely never will be because it would be rather heavy-handed for RubyGems to allow gem developers to require that users have a specific version control system installed to access a gem. Gems should be self-contained with a minimal number of dependencies so that people can use them in as wide an array of application as possible.

If you want to do this for your own internal projects, my suggestion would be to use Bundler which supports this quite well.

like image 191
gtd Avatar answered Nov 15 '22 18:11

gtd


EDIT

According to a commenter, this is no longer true. Prior information retained for historical context.

Duplicating the reference to a gem in Gemfile and .gemspec now appears to raise a warning message in Bundler, so this answer would appear to be no longer true.

Outdated info

This article by Yehuda Katz cleared up similar confusion for me. It says that, for use in development only, it's best to add the git stuff into the gemfile, but that bundler will still use the dependency/version info from the gemspec (seems magical to me, but I trust Yehuda).

like image 14
heartpunk Avatar answered Nov 15 '22 20:11

heartpunk


I just was trying to figure this problem out as well. And I just came up with the following solution (which I'm not sure if your publishing your gem or have rights to redistribute that oauth2 gem).

In your gem that requires oauth2 gem run this.

git submodule add [email protected]:lgs/oauth2.git lib/oauth2

If you require a different branch than the default

cd lib/oauth2 && git checkout <branchname_or_ref>
cd .. && git add lib/oauth2
git commit -m "adding outh2 submodule"

In your gemspec add this above your require version line

$:.push File.expand_path('../lib/oauth2/lib', __FILE__)

Also you'll need to add all of the oauth2 gem's runtime dependencies to your gemspec. I haven't figured out a way around this yet.

This is what I did, and it works for us because our gem is required via git so I'm not sure if this would work for a rubygems published gem.

like image 7
kwbock Avatar answered Nov 15 '22 19:11

kwbock