Using group in gemfile for different gem versions

1,100 views
Skip to first unread message

Tommy Chheng

unread,
Sep 13, 2011, 9:30:04 PM9/13/11
to ruby-b...@googlegroups.com
I'm trying to include a different version gem depending on the app environment group.

When I do:
gem 'xxxx', :git => 'g...@github.com:xxxx.git', :tag => 'v0.0.2', :group => [:production]
gem 'xxxx', :git => 'g...@github.com:xxxx.git', :group => [:development, :test, :staging]

You cannot specify the same gem twice coming from different sources. You specified that xxxx (>= 0) should come from g...@github.com:xxxx.git (at v0.0.2) and g...@github.com:xxxx.git (at master)

Is this possible to do with bundler?

Michael B. Klein

unread,
Sep 15, 2011, 1:56:49 AM9/15/11
to ruby-bundler
I came here searching for an answer to a very similar question, but I
ended up with something that's working for me (for now).

I have a locally-developed gem that stands alone, and also serves as
the core of my Rails app. I need my Rails app's bundle to use a
different version of the gem depending on my environment:

development: Check for a local copy. If it's there, use it. If not,
pull from our git repo on the 'develop' branch
test: Pull from our git repo on the 'test' branch
production: Install the deployed gem from our local gem server (which
is listed as a source at the top of the Gemfile)

I haven't worked with it enough to see if it has any implications for
deployment, or if it will wreak havoc with my Gemfile.lock, but here's
what I've done:

my_gem_spec = ">= 1.1.0"
group :development do
if File.directory?("/path/to/local/working/copy") ?
my_gem_spec = { :path => "/path/to/local/working/copy" }
else
my_gem_spec = { :git => "git://local/git/repo/mygem.git", :branch
=> "develop" }
end
end
group :test do
my_gem_spec = { :git => "git://local/git/repo/mygem.git", :branch =>
"test" }
end
gem "my-gem", my_gem_spec

So the 'gem "my-gem"' directive only occurs once, but it gets
different arguments/options depending on the environment. I can then
"bundle install --without='development test'" for production, etc.

It's a bit clunky, but working well so far in my dev and test
environments. I haven't tried a production deployment since setting
this up, but I have no reason to believe it won't work at least
reasonably well.

Michael

On Sep 13, 6:30 pm, Tommy Chheng <tommy.chh...@gmail.com> wrote:
> I'm trying to include a different version gem depending on the app
> environment group.
>
> When I do:
> gem 'xxxx', :git => '...@github.com:xxxx.git', :tag => 'v0.0.2', :group =>
> [:production]
> gem 'xxxx', :git => '...@github.com:xxxx.git', :group => [:development,

Alex Chaffee

unread,
Sep 15, 2011, 9:47:42 PM9/15/11
to ruby-b...@googlegroups.com, ruby-bundler
What you're trying to do is, at least on the surface, contrary to the whole mission of Bundler! :-) It's all about making sure you're running the *same* gem versions on dev and prod...

That said, here are a couple of other things you could try:

- Use :path to point to a local non-version-controlled dir and then use other means to check out / unpack the desired version on each box.

- Use different Gemfiles and the --gemfile= switch to bundle install/exec/etc.

I use the second technique to run different test suites testing the Erector library in different version of Rails: see http://github.com/pivotal/erector (look for the spec tasks in Rakefile).

HTH

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
> To post to this group, send email to ruby-b...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-bundler...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-bundler?hl=en.
>

Reply all
Reply to author
Forward
0 new messages