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:
我正在帮助开发一系列相互关联的宝石。因此,我不希望它们彼此之间存在硬依赖关系,但我确实希望它们在开发中运行彼此使用的测试。简单吧?只需在gemspec中使用add_development_dependency,对吧?好吧,有一点点皱纹 - git存储库包含所有的gem,所以我希望Gemfile指向gem的本地副本。这适用于硬依赖。在gemspec中,我有这条线用于我的硬依赖:
s.add_dependency "mygem-core"
And then in the Gemfile, I have this line:
然后在Gemfile中,我有这一行:
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:
这完美。当我推出这个包时,存在依赖性,当我测试时,它将使用mygem-core的本地副本。问题是当我把它放在gemspec中时:
s.add_development_dependency "mygem-runtime"
And then this in the Gemfile:
然后在Gemfile中:
gem "mygem-runtime", :path => "../mygem-runtime"
Then I get an error when I run bundle:
然后我运行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?
是的,这不是最后的错字。第二个“位置”的末端确实有一个空白的空白空间。有没有聪明的方法可以解决这个问题?我想将此添加为开发依赖项,并使用本地源。我错过了什么?
2 个解决方案
#1
9
It's probably better that you leave that gem out of the .gemspec manifest and put it in the Gemfile under the :development group.
将gem从.gemspec清单中删除并将其放在:development组下的Gemfile中可能会更好。
# Gemfile
source :rubygems
gemspec
gem "mygem-runtime", :path => '../mygem-runtime', :group => :development
#2
1
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.
如果您使用Gemfile来指定gem的本地路径,则需要将其从gemspec中删除。 Bundler将解析gemspec并添加Bundler正在安装的依赖项,因此它就像指定了两次gem一样。
#1
9
It's probably better that you leave that gem out of the .gemspec manifest and put it in the Gemfile under the :development group.
将gem从.gemspec清单中删除并将其放在:development组下的Gemfile中可能会更好。
# Gemfile
source :rubygems
gemspec
gem "mygem-runtime", :path => '../mygem-runtime', :group => :development
#2
1
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.
如果您使用Gemfile来指定gem的本地路径,则需要将其从gemspec中删除。 Bundler将解析gemspec并添加Bundler正在安装的依赖项,因此它就像指定了两次gem一样。