Build Gerrit in headless mode

  buck build headless

produces binary artifact without GWT.

Change-Id: Ic98312e9924d32057d6876effbdf12e489d44a8b
diff --git a/.buckconfig b/.buckconfig
index e4a19f1..e3d0ffc 100644
--- a/.buckconfig
+++ b/.buckconfig
@@ -9,6 +9,7 @@
   docs = //Documentation:searchfree
   firefox = //:firefox
   gerrit = //:gerrit
+  headless = //:headless
   release = //:release
   safari = //:safari
   soyc = //gerrit-gwtui:ui_soyc
diff --git a/BUCK b/BUCK
index 2cd3fa8..02ee883 100644
--- a/BUCK
+++ b/BUCK
@@ -1,6 +1,7 @@
 include_defs('//tools/build.defs')
 
 gerrit_war(name = 'gerrit')
+gerrit_war(name = 'headless', ui = None)
 gerrit_war(name = 'chrome',   ui = 'ui_chrome')
 gerrit_war(name = 'firefox',  ui = 'ui_firefox')
 gerrit_war(name = 'safari',   ui = 'ui_safari')
diff --git a/Documentation/dev-buck.txt b/Documentation/dev-buck.txt
index 6bd3905..c234651 100644
--- a/Documentation/dev-buck.txt
+++ b/Documentation/dev-buck.txt
@@ -116,6 +116,20 @@
 ----
 
 
+=== Headless Mode
+
+To build Gerrit in headless mode, i.e. without the GWT Web UI:
+
+----
+  buck build headless
+----
+
+The output executable WAR will be placed in:
+
+----
+  buck-out/gen/headless.war
+----
+
 === Extension and Plugin API JAR Files
 
 To build the extension, plugin and GWT API JAR files:
diff --git a/tools/build.defs b/tools/build.defs
index 8b858cd..da07c1e 100644
--- a/tools/build.defs
+++ b/tools/build.defs
@@ -71,8 +71,8 @@
     context = [
       '//gerrit-main:main_bin',
       '//gerrit-war:webapp_assets',
-      '//gerrit-gwtui:' + ui,
-    ] + context,
+    ] + (['//gerrit-gwtui:' + ui] if ui else []) +
+    context,
     docs = docs,
     visibility = visibility,
   )