Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gem and bundler: Adding a development dependency with a relative path

Tags:

I'm helping on the development of a series of interrelated gems. As such, I don't want them to have a hard dependency on each other, but I do want them to run tests in development that use each other. Simple right? Just use add_development_dependency in the gemspec, right? Well, there is one little wrinkle - the git repository contains all the gems, and so I want the Gemfile to point to the local copy of the gem. This works with a hard dependency. In the gemspec, I have this line for my hard dependency:

s.add_dependency "mygem-core"

And then in the Gemfile, I have this line:

gem "mygem-core", :path => "../mygem-core"

This works PERFECT. The dependency exists for when I push this package out, and when I'm testing, it will use the local copy of mygem-core. The problem is that when I put THIS in the gemspec:

s.add_development_dependency "mygem-runtime"

And then this in the Gemfile:

gem "mygem-runtime", :path => "../mygem-runtime"

Then I get an error when I run bundle:

You cannot specify the same gem twice coming from different sources. You specified that mygem-packager (>= 0) should come from source at ../mygem-packager and 

Yes, that's not a typo at the end. There is literally a blank, empty space at the end for the second 'location'. Is there any smart ways to work around this? I want to add this as a development dependency, and use the local source. What am I missing?

like image 677
jasonpgignac Avatar asked Jun 12 '11 02:06

jasonpgignac


People also ask

Where do I put Gemfile?

A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .

How do I install bundles to install missing gems?

Select Tools | Bundler | Install from the main menu. Open the Gemfile, place the caret at any highlighted gem missing in the project SDK and press Alt+Enter . Select Install missing gems using 'bundler' and press Enter .

How do I run a .gemfile file?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from. Save this answer.

What is a .gem file?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


2 Answers

It's probably better that you leave that gem out of the .gemspec manifest and put it in the Gemfile under the :development group.

# Gemfile
source :rubygems
gemspec

gem "mygem-runtime", :path => '../mygem-runtime', :group => :development
like image 194
Rico Sta. Cruz Avatar answered Oct 09 '22 11:10

Rico Sta. Cruz


If your using Gemfile to specificy a local path to a gem you will need to remove it from gemspec. Bundler will parse gemspec and add the dependencies those bundler is installing, so its like having the gem specified twice.

like image 33
Kris Avatar answered Oct 09 '22 11:10

Kris