[英]How to require a specific gem version in rails gemfile?
When installing a gem via bundle install
in rails 4, I get the following error: 通过在rails 4中
bundle install
来安装gem时,出现以下错误:
Bundler could not find compatible versions for gem "tzinfo":
In Gemfile:
rails (= 4.2.0) ruby depends on
actionmailer (= 4.2.0) ruby depends on
actionpack (= 4.2.0) ruby depends on
activesupport (= 4.2.0) ruby depends on
tzinfo (~> 1.1) ruby
eventbrite-client (>= 0) ruby depends on
tzinfo (~> 0.3.22) ruby
I have tried to solve this with bundle update
but that resolves in the same issue. 我试图通过
bundle update
解决此问题,但是可以解决同一问题。
Now the question is, how can I make the gem eventbrite-client
dependent on version 0.3.22 of tzinfo
. 现在的问题是,如何使gem eventbrite
eventbrite-client
依赖于tzinfo
0.3.22版本。 I cannot figure out the syntax as I tried: 我尝试时无法弄清楚语法:
gem 'eventbrite-client', :require => 'tzinfo','0.3.22'
Is this even possible? 这有可能吗?
If you want to make event-brite client work somehow then you can simply bump the version of tzinfo dependency in eventbrite gemspec file. 如果您想使Event-brite客户端以某种方式工作,则可以在eventbrite gemspec文件中简单修改tzinfo依赖项的版本。
First clone the following repository 首先克隆以下存储库
git clone git@github.com:ryanjarvinen/eventbrite-client.rb.git
Then replace the content of eventbrite-client.gemspec file with the following. 然后将eventbrite-client.gemspec文件的内容替换为以下内容。
Gem::Specification.new do |s|
s.name = %q{eventbrite-client}
s.version = "0.1.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ryan Jarvinen"]
s.date = %q{2011-08-28}
s.description = %q{A tiny EventBrite API client. (http://developer.eventbrite.com)}
s.email = %q{ryan.jarvinen@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
"README.md"
]
s.files = [
".document",
"LICENSE",
"README.md",
"Rakefile",
"VERSION",
"eventbrite-client.gemspec",
"lib/eventbrite-client.rb",
]
s.homepage = %q{http://github.com/ryanjarvinen/eventbrite-client.rb}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.6.2}
s.summary = %q{A tiny EventBrite API client}
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
s.add_runtime_dependency(%q<httparty>, ["~> 0.8.0"])
s.add_runtime_dependency(%q<tzinfo>, ["~> 1.1"])
else
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
s.add_dependency(%q<httparty>, ["~> 0.8.0"])
s.add_dependency(%q<tzinfo>, ["~> 1.1"])
end
else
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
s.add_dependency(%q<httparty>, ["~> 0.8.0"])
s.add_dependency(%q<tzinfo>, ["~> 1.1"])
end
end
And then you can rebuild the gem with 然后,您可以使用
gem build eventbrite-client.gemspec
Install it using 使用安装
gem install ./name_of_the_gem.gem
I don't think your idea would be possible (if you want to have a working rails 4.2
in the same time). 我认为您的想法是不可能的(如果您想同时拥有一个工作的
rails 4.2
)。 As bundler says- rails 4.2 requires tzinfo v1.1
therefore older versions of it won't be acceptable for rails. 正如捆绑程序所说,rails 4.2需要
tzinfo v1.1
因此它的旧版本将不被rails接受。 2 different versions of same gem in a working application aren't allowed because how would the code make a difference which one to use? 不允许在一个正常运行的应用程序中使用2个不同版本的同一gem,因为这些代码将使使用哪个代码有所不同?
Maybe a helpful answer about having two different versions of gems in one application simultaneously: Can you have multiple versions of a gem in a Gemfile? 关于在一个应用程序中同时拥有两个不同版本的gem,可能是一个有用的答案: Gemfile中可以有多个版本的gem吗?
Another answer about 2 gems having conflicting dependencies and possibilities of resolving the problem: How to override gem dependency? 关于2个具有冲突依赖关系的gems以及解决问题的可能性的另一个答案: 如何覆盖gem依赖关系? but I guess it is not possible in your case.
但我想这不可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.