Specifying the same gem twice for development/test and production but different paths
Sometimes you make a gem that is specific to a project. This helps abstract and pull some of the “responsibility” out of the main Rails app and into a more modular place.
The gem would be located here on you application:
- How is a submodule that contains a gem project have its resources required from a surrounding gem project?
- How can I display a 'last-deployed' timestamp from within my Heroku Rails app?
- How to manage Rails database.yml
- Merge branch 'user' in git log
- Use one “main project” as source for many projects: how to do it best with GitHub?
- configuring .gems file (rails apps on Heroku)
gem 'example_gem', path: './example_gem'
group :development, :test do gem 'example_gem', path: './example_gem' end group :production do gem 'example_gem', github: 'company/example_gem' end
You pat yourself on the back for increasing your workflow, but after running
bundle you get:
Your Gemfile lists the gem example_gem (>= 0) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of just one of them later. You cannot specify the same gem twice coming from different sources. You specified that example_gem (>= 0) should come from source at ./example_gem and git://github.com/company/example_gem.git
The workflow here is to be able to edit the gem in development and when you’re done, commit those changes and push them to Github. BUT, when on development, you don’t want to have to do a git commit, git push, and a bundle update on your main app just to see a small change.
Does anyone know of a better way to solve this issue?
2 Solutions collect form web for “Specifying the same gem twice for development/test and production but different paths”
Yes, there is a better way:
Have the gem as a regular git gem in all environments
gem :example_gem, :git => 'firstname.lastname@example.org:foo/example_gem', :branch => :master #you need to set a branch
Then in your app’s folder run
bundle config --local local.example_gem /path/to/gem
This will edit .bundle/config to set this option (make sure this file isn’t checked into source control!) and tells bundler to get the gem from that path.
At the point when you are going to push your commits you have to be a little bit careful: if your app depends on not yet committed changes to the gem then clearly things will break. In addition as you commit to the repository for the example gem the rails app’s Gemfile.lock will get updated. If you push a Gemfile.lock that references a commit that only exists in your copy of the example_gem repo then other users will be stuck.
this works for me.
foo = "https://github.com/me/my-development-version-gem.git" group :production do foo = "https://github.com/me/my-production-version-gem.git" end gem "foo", :git => foo
in my case i need different branchs for envs to engine