Question

There is a common pattern:

there are many developers working on one project and the Gemfile(.lock) is shared via SCM. But what if some developers want to use different tools for testing and development? How to do it?

The problem is, that when you put conditional sections to your Gemfile, also the Gemfile.lock will be different for each developer and therefor you'll get conflict each time you commit to SCM.

Is there some simple, widely acknowledged solution?

Was it helpful?

Solution 6

I suppose the install_if method (added recently) solves the problem:

install_if -> { `whoami`.strip == 'jakub' } do
  gem "pry-rails"
end

See http://bundler.io/v1.14/man/gemfile.5.html#INSTALL_IF

OTHER TIPS

I like to have this in my Gemfile:

local_gemfile = File.dirname(__FILE__) + "/Gemfile.local"
if File.file?(local_gemfile)
  require local_gemfile
end

I also have Gemfile.local and Gemfile.lock in gitignore. I know I'm not "supposed to", but I don't think the caveats (such as the ones you mention in your question) are worth it.

UPDATE for Bundler 1.0.10 as of March 3, 2011

local_gemfile = File.dirname(__FILE__) + "/Gemfile.local.rb"
if File.file?(local_gemfile)
  self.instance_eval(Bundler.read_file(local_gemfile))
end

I had to use this with Rails 3 and Bundler 1.0.10.

If you check in something that depends on a gem that gem should be in the gemfile. If the code in the repository does not depend on a gem, there's no need to have it in the gemfile. So, unless your developers don't check in their tests (which would be weird) you would need all the test's dependencies if you want to run the whole tests suite anyway.

If the gems aren't necessary to run the app or its tests the gems don't need to be in the gemfile. Just have each developer create a gemset (I assume you're using RVM, if you don't you should) for the app and install whatever they need there, and then just add what the app needs to run to the gemfile.

You can use Bundler's without flag to exclude groups.

If you have the following Gemfile

group :jakubs_testing_tools do
  gem "rspec"
  gem "faker"
end

You can exclude them with bundle install

$ bundle install --without jakubs_testing_tools

http://gembundler.com/groups.html

It won't help you right now, but there's been an open feature request for Bundler to add support for a Gemfile.local for ages. It is planned for somewhere in the 1.x series, so stay tuned.

If your main problem is developer-specific IRB gems, there are a couple of workarounds in the issue's comments.

Each developer can create their own branch - Bundler works fine with different branches having different Gemfile contents. It's a good idea for developers to prefix branch names with their initials, to avoid confusion or collisions.

(basically the same idea as in August Lilleaas's comment: gitignore)

Put the default/minimal Gemfile in SCM and then have developers change it on their systems and never commit. Have them add it to their inactive changeset in their SVN client (if they use one), other SCMs should have something similar.

This is how we do this in my company - works really well :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top