如何在gemspec中向私有gem添加依赖项?

[英]How do I add a dependency to a private gem in gemspec?


I'm trying to add a private gem dependency to a gemspec I'm writing. My Gemfile is:

我正在尝试将一个私有宝石依赖项添加到我正在编写的gemspec中。我的Gemfile是:

source 'https://rubygems.org'

gemspec

gem 'my_private_gem', '0.0.1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git'

And the relevant line in mygem.gemspec is:

而mygem.gemspec中的相关行是:

spec.add_dependency 'my_private_gem', '0.0.1'

Now I thought this would work but after running gem build mygem and gem install ./mygem.gem I get: ERROR: Could not find a valid gem 'mygem' (= 0.0.1) in any repository.

现在我认为这会起作用但是在运行gem build mygem和gem install ./mygem.gem之后我得到:错误:在任何存储库中都找不到有效的gem'mygem'(= 0.0.1)。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


It is possible without creating own gem server.

没有创建自己的gem服务器是可能的。

In case the URL to the gem is correct, most probably you don't have the correct 0.0.1 version specified within the gem's .gemspec file. You need to have: spec.version = '0.0.1' (the dependency you have added is like recursive dependency to itself, I'm not even sure if it can work with it)

如果gem的URL是正确的,很可能你没有在gem的.gemspec文件中指定正确的0.0.1版本。你需要:spec.version ='0.0.1'(你添加的依赖关系就像对自身的递归依赖,我甚至不确定它是否可以使用它)

Also in most cases it would be easier to have a release branch or tag to which you point the gem instead to a version. As described here: http://bundler.io/git.html You either need to have .gemspecs in the root of the gem to use it in the way you have described above. Or create a branch/tag and use one of: gem 'my_private_gem', :tag => 'v0.0.1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git' gem 'my_private_gem', :branch => 'release-0-0-1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git'

此外,在大多数情况下,将gem指向某个版本的发布分支或标记会更容易。如下所述:http://bundler.io/git.html您需要在gem的根目录中使用.gemspecs,以便按照上述方式使用它。或者创建一个分支/标记并使用以下之一:gem'my_private_gem',:tag =>'v0.0.1',:git =>'https:// username:pwd@bitbucket.org/johnny/my_private_gem.git'gem 'my_private_gem',: branch =>'release-0-0-1',:git =>'https:// username:pwd@bitbucket.org/johnny/my_private_gem.git'


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/08/2c7ebcbc1a0dee4293dca46161816865.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com