Lucene: Add back the core-and-backward-codecs target

This is needed after the upgrade to Lucene 5.4.1.

This partially reverts commit fc70ea396173a667b13272646997e222bb4d0756.

Change-Id: Ie8f4449a08ff951278863bddf39016a951a05067
diff --git a/gerrit-httpd/BUCK b/gerrit-httpd/BUCK
index f4254dc..7988cf6 100644
--- a/gerrit-httpd/BUCK
+++ b/gerrit-httpd/BUCK
@@ -36,7 +36,7 @@
     '//lib/jgit:jgit',
     '//lib/jgit:jgit-servlet',
     '//lib/log:api',
-    '//lib/lucene:lucene-core',
+    '//lib/lucene:lucene-core-and-backward-codecs',
   ],
   provided_deps = ['//lib:servlet-api-3_1'],
   visibility = ['PUBLIC'],
diff --git a/gerrit-lucene/BUCK b/gerrit-lucene/BUCK
index e9490d0..5a6df97 100644
--- a/gerrit-lucene/BUCK
+++ b/gerrit-lucene/BUCK
@@ -11,7 +11,7 @@
     '//gerrit-server:server',
     '//lib:gwtorm',
     '//lib:guava',
-    '//lib/lucene:lucene-core',
+    '//lib/lucene:lucene-core-and-backward-codecs',
   ],
   visibility = ['PUBLIC'],
 )
@@ -34,7 +34,7 @@
     '//lib/jgit:jgit',
     '//lib/log:api',
     '//lib/lucene:lucene-analyzers-common',
-    '//lib/lucene:lucene-core',
+    '//lib/lucene:lucene-core-and-backward-codecs',
     '//lib/lucene:lucene-misc',
   ],
   visibility = ['PUBLIC'],
diff --git a/gerrit-server/BUCK b/gerrit-server/BUCK
index c98663a..567754f 100644
--- a/gerrit-server/BUCK
+++ b/gerrit-server/BUCK
@@ -65,7 +65,7 @@
     '//lib/log:jsonevent-layout',
     '//lib/log:log4j',
     '//lib/lucene:lucene-analyzers-common',
-    '//lib/lucene:lucene-core',
+    '//lib/lucene:lucene-core-and-backward-codecs',
     '//lib/lucene:lucene-queryparser',
     '//lib/ow2:ow2-asm',
     '//lib/ow2:ow2-asm-tree',
diff --git a/lib/asciidoctor/BUCK b/lib/asciidoctor/BUCK
index f9b5b30..98ad93c 100644
--- a/lib/asciidoctor/BUCK
+++ b/lib/asciidoctor/BUCK
@@ -36,7 +36,7 @@
     '//lib:args4j',
     '//lib:guava',
     '//lib/lucene:lucene-analyzers-common',
-    '//lib/lucene:lucene-core',
+    '//lib/lucene:lucene-core-and-backward-codecs',
   ],
   visibility = ['//tools/eclipse:classpath'],
 )
diff --git a/lib/lucene/BUCK b/lib/lucene/BUCK
index 524f605..fdf8129 100644
--- a/lib/lucene/BUCK
+++ b/lib/lucene/BUCK
@@ -2,6 +2,17 @@
 
 VERSION = '5.4.1'
 
+# core and backward-codecs both provide
+# META-INF/services/org.apache.lucene.codecs.Codec, so they must be merged.
+merge_maven_jars(
+  name = 'lucene-core-and-backward-codecs',
+  srcs = [
+    ':backward-codecs_jar',
+    ':lucene-core',
+  ],
+  visibility = ['PUBLIC'],
+)
+
 maven_jar(
   name = 'lucene-core',
   id = 'org.apache.lucene:lucene-core:' + VERSION,
@@ -11,6 +22,7 @@
     'META-INF/LICENSE.txt',
     'META-INF/NOTICE.txt',
   ],
+  visibility = [],
 )
 
 maven_jar(
@@ -18,7 +30,7 @@
   id = 'org.apache.lucene:lucene-analyzers-common:' + VERSION,
   sha1 = 'c2aa2c4e00eb9cdeb5ac00dc0495e70c441f681e',
   license = 'Apache2.0',
-  deps = [':lucene-core'],
+  deps = [':lucene-core-and-backward-codecs'],
   exclude = [
     'META-INF/LICENSE.txt',
     'META-INF/NOTICE.txt',
@@ -26,11 +38,24 @@
 )
 
 maven_jar(
+  name = 'backward-codecs_jar',
+  id = 'org.apache.lucene:lucene-backward-codecs:' + VERSION,
+  sha1 = '5273da96380dfab302ad06c27fe58100db4c4e2f',
+  license = 'Apache2.0',
+  deps = [':core_jar'],
+  exclude = [
+    'META-INF/LICENSE.txt',
+    'META-INF/NOTICE.txt',
+  ],
+  visibility = [],
+)
+
+maven_jar(
   name = 'lucene-misc',
   id = 'org.apache.lucene:lucene-misc:' + VERSION,
   sha1 = '95f433b9d7dd470cc0aa5076e0f233907745674b',
   license = 'Apache2.0',
-  deps = [':lucene-core'],
+  deps = [':lucene-core-and-backward-codecs'],
   exclude = [
     'META-INF/LICENSE.txt',
     'META-INF/NOTICE.txt',
@@ -42,7 +67,7 @@
   id = 'org.apache.lucene:lucene-queryparser:' + VERSION,
   sha1 = 'dccd5279bfa656dec21af444a7a66820eb1cd618',
   license = 'Apache2.0',
-  deps = [':lucene-core'],
+  deps = [':lucene-core-and-backward-codecs'],
   exclude = [
     'META-INF/LICENSE.txt',
     'META-INF/NOTICE.txt',