Using group in gemfile for different gem versions

Showing 1-3 of 3 messages
Using group in gemfile for different gem versions Tommy Chheng 9/13/11 6:30 PM
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 git@github.com:xxxx.git (at v0.0.2) and git@github.com:xxxx.git (at master)

Is this possible to do with bundler?
Re: Using group in gemfile for different gem versions Michael B. Klein 9/14/11 10:56 PM
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,
> :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)
Re: Using group in gemfile for different gem versions Alex Chaffee 9/15/11 6:47 PM
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.
>