Ruby 请教一下 gem 依赖的 gem 的 constant 冲突了怎么解决

doraemon0711 · 2022年03月31日 · 最后由 franklinyu 回复于 2022年04月11日 · 372 次阅读

用到了 a 和 b 两个 gem
a gem 依赖了 protobuf
b gem 依赖了 google-protobuf
现在启动程序会提示很多警告

/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:11: warning: already initialized constant Google::Protobuf::FileDescriptorSet
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:15: warning: previous definition of FileDescriptorSet was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:12: warning: already initialized constant Google::Protobuf::FileDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:16: warning: previous definition of FileDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:13: warning: already initialized constant Google::Protobuf::DescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:17: warning: previous definition of DescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:16: warning: already initialized constant Google::Protobuf::ExtensionRangeOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:23: warning: previous definition of ExtensionRangeOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:17: warning: already initialized constant Google::Protobuf::FieldDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:24: warning: previous definition of FieldDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:20: warning: already initialized constant Google::Protobuf::OneofDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:54: warning: previous definition of OneofDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:21: warning: already initialized constant Google::Protobuf::EnumDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:55: warning: previous definition of EnumDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:23: warning: already initialized constant Google::Protobuf::EnumValueDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:60: warning: previous definition of EnumValueDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:24: warning: already initialized constant Google::Protobuf::ServiceDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:61: warning: previous definition of ServiceDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:25: warning: already initialized constant Google::Protobuf::MethodDescriptorProto
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:62: warning: previous definition of MethodDescriptorProto was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:26: warning: already initialized constant Google::Protobuf::FileOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:63: warning: previous definition of FileOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:28: warning: already initialized constant Google::Protobuf::MessageOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:72: warning: previous definition of MessageOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:29: warning: already initialized constant Google::Protobuf::FieldOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:73: warning: previous definition of FieldOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:32: warning: already initialized constant Google::Protobuf::OneofOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:88: warning: previous definition of OneofOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:33: warning: already initialized constant Google::Protobuf::EnumOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:89: warning: previous definition of EnumOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:34: warning: already initialized constant Google::Protobuf::EnumValueOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:90: warning: previous definition of EnumValueOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:35: warning: already initialized constant Google::Protobuf::ServiceOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:91: warning: previous definition of ServiceOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:36: warning: already initialized constant Google::Protobuf::MethodOptions
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:92: warning: previous definition of MethodOptions was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:38: warning: already initialized constant Google::Protobuf::UninterpretedOption
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:101: warning: previous definition of UninterpretedOption was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:40: warning: already initialized constant Google::Protobuf::SourceCodeInfo
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:106: warning: previous definition of SourceCodeInfo was here
/gems/google-protobuf-3.19.3-x86_64-darwin/lib/google/protobuf/descriptor_pb.rb:42: warning: already initialized constant Google::Protobuf::GeneratedCodeInfo
/gems/protobuf-3.10.5/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb:111: warning: previous definition of GeneratedCodeInfo was here

不知道是不是因为这个原因 spring 经常卡住 - -

a 或 b 去掉,或者找不冲突的替代 gem.

a 和 b 都用了 protobuf 功能,它们本身会不会可以相互替代

protobuf 是第三方的 ProtoBuf 實現,不是谷歌官方的包。或許可以和 a 的作者商量一下,改用 google-protobuf

需要 登录 后方可回复, 如果你还没有账号请 注册新账号