Implement jarjar for icing protos.
This is required to avoid the diamond dependency problem for users of
our lib who also use a separate version of protobuf.
This implementation of jarjar is based on the jarjar of flatbuffers for
emoji-compat.
Bug: 153380375
Test: ./gradlew appsearch:appsearch:connectedCheck --daemon --info
Change-Id: I8495b0a0a70d6e2c5f16683895d3b1879de610ec
diff --git a/java/build.gradle b/java/build.gradle
index 7f75fd5..caaa116 100644
--- a/java/build.gradle
+++ b/java/build.gradle
@@ -24,11 +24,13 @@
}
dependencies {
classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.8')
+ classpath('org.anarres.jarjar:jarjar-gradle:1.0.1')
}
}
apply plugin: 'java-library'
apply plugin: 'com.google.protobuf'
+apply plugin: 'org.anarres.jarjar'
apply plugin: 'idea'
sourceSets {
@@ -40,8 +42,13 @@
}
}
+compileJava {
+ sourceCompatibility = JavaVersion.VERSION_1_7
+ targetCompatibility = JavaVersion.VERSION_1_7
+}
+
dependencies {
- api('com.google.protobuf:protobuf-javalite:3.10.0')
+ implementation('com.google.protobuf:protobuf-javalite:3.10.0')
}
protobuf {
@@ -59,3 +66,23 @@
}
}
}
+
+jarjar.repackage('jarjarTask') {
+ destinationName "icing-java-jarjar.jar"
+ from 'com.google.protobuf:protobuf-javalite:3.10.0'
+ from files(sourceSets.main.output.classesDirs)
+ dependsOn sourceSets.main.output
+ classRename 'com.google.protobuf.**', 'com.google.android.icing.protobuf.@1'
+}
+
+configurations {
+ jarjarConf
+}
+
+artifacts {
+ jarjarConf(jarjarTask.destinationPath) {
+ name 'icing-java-jarjar'
+ type 'jar'
+ builtBy jarjarTask
+ }
+}