将 protobuf3 与某些依赖于 Java 中的 protobuf2 的库一起使用
use protobuf3 with some lib which depends on protobuf2 in Java
我正在使用 protobuf3 来表示我们的数据,而我们需要 hbase 来存储数据,hbase 似乎依赖于 protobuf2。
当我编写以下行来创建我们的 hbase table
admin.createTable(desc);
然后我得到了一个例外:NoClassDefFoundError: com/google/protobuf/LiteralByteString
我试过使用 gradle's shadow plugin 将 com.google.protobuf 重新定位到 shadow.google.com,然后它会抛出类似的消息 NoClassDefFoundError: shadow/google/protobuf/LiteralByteString
。
- 创建一个子项目,并命名为'hbase-wrapper'
- 将 hbase 的依赖项移动到新项目
- 新项目中的Shadow protobuf
- 在主工程上添加子工程的依赖
这是一些代码片段
// part of build.gradle of the sub-project
...
dependencies {
compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.2.4'
}
shadowJar {
relocate('com.google.protobuf', 'hbasesaver.google.protobuf')
}
// part of build.gradle for main project
...
compile project(path: ':hbase-wrapper', configuration: 'shadow')
我正在使用 protobuf3 来表示我们的数据,而我们需要 hbase 来存储数据,hbase 似乎依赖于 protobuf2。
当我编写以下行来创建我们的 hbase table
admin.createTable(desc);
然后我得到了一个例外:NoClassDefFoundError: com/google/protobuf/LiteralByteString
我试过使用 gradle's shadow plugin 将 com.google.protobuf 重新定位到 shadow.google.com,然后它会抛出类似的消息 NoClassDefFoundError: shadow/google/protobuf/LiteralByteString
。
- 创建一个子项目,并命名为'hbase-wrapper'
- 将 hbase 的依赖项移动到新项目
- 新项目中的Shadow protobuf
- 在主工程上添加子工程的依赖
这是一些代码片段
// part of build.gradle of the sub-project
...
dependencies {
compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.2.4'
}
shadowJar {
relocate('com.google.protobuf', 'hbasesaver.google.protobuf')
}
// part of build.gradle for main project
...
compile project(path: ':hbase-wrapper', configuration: 'shadow')