开发者

How can I use the "gemspec" rule in Bundler, while still using a local checkout of a gem?

Scenario: I am developing a gem gem-foo, using Bundler. I have a dependency on gem-bar, which I have checked out locally for development. I can declare this dependency in the Gemfile as:

gem "gem-bar", :path => "/path/to/local/gem-bar"

However, when developing a gem the "best practice" seems t开发者_如何学Co be to define the required gems in the gem-foo.gemspec via:

s.add_runtime_dependency 'gem-bar'

and then simply include the dependencies in the Gemfile using:

gemspec

What I would like to do is to add the runtime dependency on the gem in the gemspec, but make some local modifications to gem-bar and have a bundle install use the local development checkout. Assume the case where I control both gems, and am hacking on them somewhat concurrently, and I'll be pushing the new versions simultaneously. I could just comment out the s.add_runtime_dependency in the gemspec and add it with the local path in the Gemfile, but that feels... error-prone? The gemspec should always declare this dependency, and the Gemfile should be able to override the location Bundler should use for the gem. However, if you actually do this, you get the following error:

You cannot specify the same gem twice coming from different sources. You specified that gem-bar (>= 0) should come from an unspecfied source and source at /path/to/local/gem-bar

Ideally, I'd just have some sort of local override, since I never want the case where I accidentally push the gem with the requirement of a local gem-bar at a specific path. That would be dumb.

Does anyone have a good solution to this use case?


A few people have found this problem, Yehuda Katz has said he would happily accept a patch: http://groups.google.com/group/ruby-bundler/browse_thread/thread/d4215c4930a63ffc?pli=1

As the best workaround, comment out the gemspec line in your gemfile and suffer some duplication?

Update:

It looks like you don't have to wait - https://github.com/carlhuda/bundler/commit/03378109d

The commit message: "Make it possible to override a .gemspec dependency's source in the Gemfile"

hooray!


For now, what I've done is to disable gem requirements in the gemspec when a given environment variable is set, then in the Gemfile, add a gem definition that points to my local filesystem.

I wrote about my whole workflow here: http://numbers.brighterplanet.com/2010/07/28/bundler-to-the-max/ Note: I also use jeweler, which complicates things greatly.


Boy! I never get to these on time do I? Try Bundler options like --something vendor I can't remember.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜