[build] Separate protobuf java compilation into a seperate module

Currently we compile the protobufs in both the kudu-client
and the kudu-subprocess. Doing this also combines them onto
the same classpath as the module itself.

This patch breaks those classes into a separate `kudu-proto`
module so that we can avoid duplicate work and ignore
the `kudu-proto` module in API compatibility and test
coverage checks.

This module is not published, so there is no net change to the final
artifacts.

Change-Id: Ib83db74c4a09cdd597bee90f5124ed804adac42d
Reviewed-on: http://gerrit.cloudera.org:8080/16953
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
diff --git a/build-support/check_compatibility.py b/build-support/check_compatibility.py
index 52e82b4..24762cc 100755
--- a/build-support/check_compatibility.py
+++ b/build-support/check_compatibility.py
@@ -132,6 +132,7 @@
       "kudu-backup" not in j and
       "kudu-hive" not in j and
       "kudu-jepsen" not in j and
+      "kudu-proto" not in j and
       "kudu-subprocess" not in j)]
 
 
diff --git a/java/kudu-client/build.gradle b/java/kudu-client/build.gradle
index 8e655ff..082b7d9 100644
--- a/java/kudu-client/build.gradle
+++ b/java/kudu-client/build.gradle
@@ -15,11 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-apply from: "$rootDir/gradle/protobuf.gradle"
 apply from: "$rootDir/gradle/shadow.gradle"
 apply from: "$rootDir/gradle/benchmarks.gradle"
 
 dependencies {
+  compile project(path: ":kudu-proto")
   // Not shaded in the client JAR because it's part of the public API.
   compileUnshaded(libs.async) {
     // async uses versions ranges for slf4j making builds non-deterministic.
@@ -32,7 +32,6 @@
   compile libs.micrometerCore
   compile libs.murmur
   compile libs.netty
-  compile libs.protobufJava
 
   optional libs.jsr305
   optional libs.yetusAnnotations
@@ -44,14 +43,3 @@
   testCompile libs.log4jSlf4jImpl
   testCompile libs.mockitoCore
 }
-
-// Add protobuf files to the proto source set.
-sourceSets {
-  main {
-    proto {
-      srcDir "${project.rootDir}/../src"
-      // Excluded any test proto files
-      exclude "**/*test*.proto"
-    }
-  }
-}
diff --git a/java/kudu-proto/build.gradle b/java/kudu-proto/build.gradle
new file mode 100644
index 0000000..c32cad4
--- /dev/null
+++ b/java/kudu-proto/build.gradle
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+apply from: "$rootDir/gradle/protobuf.gradle"
+
+dependencies {
+  compile libs.protobufJava
+}
+
+// Add protobuf files to the proto source set.
+sourceSets {
+  main {
+    proto {
+      srcDir "${project.rootDir}/../src"
+      // Excluded any test proto files
+      exclude "**/*test*.proto"
+    }
+  }
+}
+
+// kudu-proto has no public Javadoc.
+javadoc {
+  enabled = false
+}
+
+// Skip publishing kudu-proto artifact because it will always be shaded into kudu-client.
+uploadArchives.enabled = false
+install.enabled = false
diff --git a/java/kudu-subprocess/build.gradle b/java/kudu-subprocess/build.gradle
index 45360aa..bef4ead 100644
--- a/java/kudu-subprocess/build.gradle
+++ b/java/kudu-subprocess/build.gradle
@@ -15,13 +15,13 @@
 // specific language governing permissions and limitations
 // under the License.
 
-apply from: "$rootDir/gradle/protobuf.gradle"
 apply from: "$rootDir/gradle/shadow.gradle"
 
 // Explicitly allow slf4j to be included in this jar.
 shadowIncludeSlf4j = true
 
 dependencies {
+  compile project(path: ":kudu-proto")
   compile(libs.hadoopCommon) {
     // hadoopCommon and rangerPlugin use different versions of jersey.
     exclude group: "com.sun.jersey"
@@ -29,7 +29,6 @@
     exclude group: "log4j"
     exclude group: "org.slf4j"
   }
-  compile libs.protobufJava
   compile libs.protobufJavaUtil
 
   compile(libs.rangerPlugin) {
@@ -54,17 +53,6 @@
   testCompile libs.mockitoCore
 }
 
-// Add protobuf files to the proto source set.
-sourceSets {
-  main {
-    proto {
-      srcDir "${project.rootDir}/../src"
-      // Excluded any test proto files
-      exclude "**/*test*.proto"
-    }
-  }
-}
-
 // kudu-subprocess has no public Javadoc.
 javadoc {
   enabled = false
diff --git a/java/settings.gradle b/java/settings.gradle
index a6c3355..0fd3ebc 100644
--- a/java/settings.gradle
+++ b/java/settings.gradle
@@ -27,6 +27,7 @@
 include "kudu-hive"
 include "kudu-jepsen"
 include "kudu-mapreduce"
+include "kudu-proto"
 include "kudu-spark"
 include "kudu-spark-tools"
 include "kudu-subprocess"