proto2 with Spark cannot run
OK, here's the solution:
relocate
is the way to rescue.
In my main program, I've a build.gradle like this:
dependencies { compile project(path: ':utils:hbasewrapper', configuration: 'shadow')}apply plugin: 'com.github.johnrengelman.shadow'shadowJar { baseName = 'awesome-jar' zip64 true // This is to avoid the conflict between proto3 we are using and the proto2 hbase is using. relocate ('com.google.protobuf', 'importer.com.google.protobuf')}
Then, I created another gradle package which has following build.gradle
group 'com.abc.hbasewrapper'version '1.0-SNAPSHOT'dependencies { compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.3.0' compile group: 'org.apache.hbase', name: 'hbase-server', version: '1.2.2'}apply plugin: 'java'apply plugin: 'com.github.johnrengelman.shadow'shadowJar { baseName = 'hbasewrapper' version = null zip64 true relocate ('com.google.protobuf', 'hbasewrapper.com.google.protobuf') relocate ('io.netty', 'hbasewrapper.io.netty')}
The root cause is due the HBase is referencing proto2 and my program is using proto3, thus causing this NoSuchMethodError
error.The solution is to use relocate
, to relocate the com.google.protobuf
to a different gradle project which sole purpose is to build the hbase jar files that has proto2.
Hope it helps other fellow programmers! ^ ^