如何在gemspec文件中指定相关gem的路径? [英] how to specify path for dependent gem in gemspec file?
问题描述
我已经创建了一个gem(X),但它没有发布。现在我正在创建另一个gem,它将把gem X添加为这样的依赖项: -
$ p $ s.add_dependencyX
在gemspec文件中。
由于gem(X)不在rubygem或git或rubyforge上,bundle install命令会引发错误:
无法找到宝石X **
我认为指定X的路径会执行诀窍,但怎么做?
我想我看到了@ bor1s在SO文章中指出的关于git引用的内容。 / p>
gemspec
文件是关于发布您的gem的依赖关系。您的 Gemfile
通常通过调用 gemspec
设置您的本地开发环境。
在你的情况下,你的 gemspec
应该有这个
s.add_dependencyX
然后你的 Gemfile
看起来像这样(确保本地引用在 gemspec
调用之后):
sourcehttp://www.rubygems.org
gemspec
gemX,:path => / Users / vikram / source / X
从Yahuda Katz的有关gemspec和Bundler的博客文章引用 b
$ b
如果您发现需要针对尚未发布的gem进行开发(例如,Rails经常会针对未发布的版本进行开发Rack,Arel或Mail宝石),您可以在Gemfile中添加个别行,告诉打包者在哪里找到宝石。它仍将使用.gemspec中列出的依赖关系来解决依赖关系,但现在它确切知道在gem开发过程中哪里可以找到依赖项。
sourcehttp://www.rubygems.org
gemspec
#如果这个git仓库中的.gemspec doesn与此
#gem的.gemspec所需的版本不匹配,bundler将打印一个错误
gemrack,::git => git://github.com/rack/rack.git
您不希望将这些信息包含在.gemspec中,这些信息最终会在发布的gem发布后发布到Rubygems。同样,这使得整个系统更具弹性,因为它不依赖于瞬时外部URL。这些信息纯粹是用来在开发过程中建立一个完整的环境的,这需要一些精确的。
I have created a gem(X) and it's not published. Now I am creating an another gem which will add the gem X as a dependency like this :-
s.add_dependency "X"
in gemspec file.
since the gem(X) is not on rubygem or git or rubyforge, the bundle install command throws the error:
could not find the gem X**
I think specifying the path for X will do the trick, but how?
I think I see what @bor1s was pointing to in the SO post about git references.
The gemspec
file is about dependencies for publishing your gem. Your Gemfile
sets up your local environment for development, usually by calling gemspec
.
In your case your gemspec
should have this
s.add_dependency "X"
And then your Gemfile
would look something like this (make sure the local reference is after the gemspec
call):
source "http://www.rubygems.org"
gemspec
gem "X", :path => "/Users/vikram/source/X"
Quoting from Yahuda Katz's blog post about gemspec and Bundler
If you find that you need to develop against a gem that hasn’t yet been released (for instance, Rails often develops against unreleased Rack, Arel, or Mail gems), you can add individual lines in the Gemfile that tell bundler where to find the gems. It will still use the dependencies listed in the .gemspec for dependency resolution, but it now knows exactly where to find the dependency during gem development.
source "http://www.rubygems.org"
gemspec
# if the .gemspec in this git repo doesn't match the version required by this
# gem's .gemspec, bundler will print an error
gem "rack", :git => "git://github.com/rack/rack.git"
You wouldn’t want to include this information in the .gemspec, which will eventually be released to Rubygems after the in-development gem has also been released. Again, this makes the overall system more resilient, as it doesn’t depend on transient external URLs. This information is purely something used to set up a complete environment during development, which requires some precision.
这篇关于如何在gemspec文件中指定相关gem的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!