blob: 4c224b5f243e08ce8fb3a9a906d3ac5c7cc51434 [file] [log] [blame]
Marian Harbachebeb1542019-12-13 10:42:46 +01001:linkattrs:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +02002= Gerrit Code Review - Building with Bazel
3
Han-Wen Nienhuys1e318032020-01-08 16:53:08 +01004[[summary]]
5== TL;DR
6
7If you have the prerequisites, running
8
9```
10 $ bazel build gerrit
11```
12
13should generate a .war file under `bazel-bin/gerrit.war`.
14
Alice Kober-Sotzekd9da89f2016-11-25 12:02:18 +010015[[installation]]
Olivier Croquettea9091192018-01-14 20:20:56 +010016== Prerequisites
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020017
Olivier Croquettea9091192018-01-14 20:20:56 +010018To build Gerrit from source, you need:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020019
Olivier Croquettea9091192018-01-14 20:20:56 +010020* A Linux or macOS system (Windows is not supported at this time)
David Ostrovsky21a891c2020-12-19 12:57:06 +010021* A JDK for Java 11 or Java 17
David Ostrovsky2b5fe092021-03-03 11:52:30 +010022* Python 3
Marian Harbach34253372019-12-10 18:01:31 +010023* link:https://github.com/nodesource/distributions/blob/master/README.md[Node.js (including npm),role=external,window=_blank]
Ben Rohlfs11876a42020-04-27 10:16:51 +020024* Bower (`npm install -g bower`)
David Pursehousebfe2d142020-01-29 18:02:53 +090025* link:https://docs.bazel.build/versions/master/install.html[Bazel,role=external,window=_blank] -launched with
26link:https://github.com/bazelbuild/bazelisk[Bazelisk,role=external,window=_blank]
Han-Wen Nienhuysf66222f2018-04-18 14:11:40 +020027* Maven
28* zip, unzip
Christian Aistleitner53345062020-04-27 14:37:08 +020029* curl
Han-Wen Nienhuysf66222f2018-04-18 14:11:40 +020030* gcc
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020031
Marco Miller9bede912020-01-27 17:38:40 -050032[[bazel]]
33=== Bazel
34
Ben Rohlfs11876a42020-04-27 10:16:51 +020035link:https://github.com/bazelbuild/bazelisk[Bazelisk,role=external,window=_blank] is a version
36manager for link:https://bazel.build/[Bazel,role=external,window=_blank], similar to how `nvm`
37manages `npm` versions. It takes care of downloading and installing Bazel itself, so you don't have
Clark Boylan8784a6c2023-09-27 16:35:19 -070038to worry about using the correct version of Bazel. One particular advantage to
39using Bazelisk is that you can jump between different versions of Gerrit and not
40worry about which version of Bazel you need.
41
42Bazelisk can be installed in different ways:
43link:https://docs.bazel.build/install-bazelisk.html[Bazelisk Installation,role=external,window=_blank].
44To execute the correct version of Bazel using Bazelisk you simply replace
45the `bazel` command with `bazelisk`.
Marco Miller9bede912020-01-27 17:38:40 -050046
David Pursehousec8b633d2019-05-08 08:36:18 +090047[[java]]
48=== Java
49
Matthias Sohn82786672021-02-25 17:19:53 +010050Ensure that the link:install.html#Requirements[required Java version]
51is installed and that `JAVA_HOME` is set to it.
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020052
53To check the installed version of Java, open a terminal window and run:
54
55`java -version`
56
David Ostrovskyb89332d2020-04-27 07:06:24 +020057[[java-11]]
58==== Java 11 support
59
David Ostrovsky2f231872022-01-11 21:51:15 +010060To build Gerrit with Java 11 language level, run:
David Ostrovskyb89332d2020-04-27 07:06:24 +020061
62```
Jacek Centkowski8f91b022023-11-16 21:56:46 +010063 $ bazelisk build --config=java11 :release
David Ostrovskyb89332d2020-04-27 07:06:24 +020064```
65
David Ostrovsky21a891c2020-12-19 12:57:06 +010066[[java-17]]
67==== Java 17 support
David Pursehousec8b633d2019-05-08 08:36:18 +090068
David Ostrovsky21a891c2020-12-19 12:57:06 +010069Java 17 is supported. To build Gerrit with Java 17, run:
David Ostrovskyf55b69f2018-08-23 08:25:24 +020070
71```
Jacek Centkowski8f91b022023-11-16 21:56:46 +010072 $ bazelisk build :release
David Ostrovskyf55b69f2018-08-23 08:25:24 +020073```
74
David Ostrovsky21a891c2020-12-19 12:57:06 +010075To run the tests with Java 17, run:
David Ostrovsky0bceb042018-08-25 07:37:54 +020076
77```
Diego Zambelli Sessona23acbe42023-11-17 15:49:36 +010078 $ bazelisk test //...
David Ostrovsky0bceb042018-08-25 07:37:54 +020079```
80
Alice Kober-Sotzek79290dc2019-05-07 19:26:18 +020081=== Node.js and npm packages
Marian Harbach34253372019-12-10 18:01:31 +010082See link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/README.md#installing-node_js-and-npm-packages[Installing Node.js and npm packages,role=external,window=_blank].
Alice Kober-Sotzek79290dc2019-05-07 19:26:18 +020083
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020084[[build]]
85== Building on the Command Line
86
87=== Gerrit Development WAR File
88
David Ostrovsky7163dac2017-07-29 06:49:38 +020089To build the Gerrit web application:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020090
91----
Clark Boylan8784a6c2023-09-27 16:35:19 -070092 bazelisk build gerrit
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020093----
94
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +020095The output executable WAR will be placed in:
96
97----
98 bazel-bin/gerrit.war
99----
100
Edwin Kempin976dc0b2016-11-14 16:34:50 -0800101[[release]]
Edwin Kempin3cfce172016-11-14 16:17:17 -0800102=== Gerrit Release WAR File
103
Ben Rohlfsda0a62b2021-04-26 17:02:19 +0200104To build the Gerrit web application that includes the Gerrit UI,
David Ostrovsky7163dac2017-07-29 06:49:38 +0200105core plugins and documentation:
Edwin Kempin3cfce172016-11-14 16:17:17 -0800106
107----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700108 bazelisk build release
Edwin Kempin3cfce172016-11-14 16:17:17 -0800109----
110
111The output executable WAR will be placed in:
112
113----
114 bazel-bin/release.war
115----
116
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200117=== Headless Mode
118
Ben Rohlfsda0a62b2021-04-26 17:02:19 +0200119To build Gerrit in headless mode, i.e. without the Gerrit UI:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200120
121----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700122 bazelisk build headless
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200123----
124
125The output executable WAR will be placed in:
126
127----
Edwin Kempin03eaa9a2016-11-14 15:45:51 -0800128 bazel-bin/headless.war
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200129----
130
131=== Extension and Plugin API JAR Files
132
David Ostrovsky7163dac2017-07-29 06:49:38 +0200133To build the extension, plugin and acceptance-framework JAR files:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200134
135----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700136 bazelisk build api
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200137----
138
David Ostrovsky26f8da82016-12-24 09:29:33 +0100139The output archive that contains Java binaries, Java sources and
140Java docs will be placed in:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200141
142----
Luca Milanesio5bd7b9b2019-06-10 10:01:02 +0100143 bazel-bin/api.zip
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200144----
145
David Ostrovsky7163dac2017-07-29 06:49:38 +0200146Install {extension,plugin,acceptance-framework}-api to the local
147maven repository:
David Ostrovsky50785fd2016-10-28 09:17:14 +0200148
149----
Edwin Kempind3bb3022017-01-24 11:28:34 +0100150 tools/maven/api.sh install
David Ostrovsky50785fd2016-10-28 09:17:14 +0200151----
152
153Install gerrit.war to the local maven repository:
154
155----
Edwin Kempind3bb3022017-01-24 11:28:34 +0100156 tools/maven/api.sh war_install
David Ostrovsky50785fd2016-10-28 09:17:14 +0200157----
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200158
159=== Plugins
160
David Ostrovskyaf719682016-09-28 20:31:18 +0200161----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700162 bazelisk build plugins:core
David Ostrovskyaf719682016-09-28 20:31:18 +0200163----
164
165The output JAR files for individual plugins will be placed in:
166
167----
Luca Milanesio5bd7b9b2019-06-10 10:01:02 +0100168 bazel-bin/plugins/<name>/<name>.jar
David Ostrovskyaf719682016-09-28 20:31:18 +0200169----
170
171The JAR files will also be packaged in:
172
173----
Luca Milanesio5bd7b9b2019-06-10 10:01:02 +0100174 bazel-bin/plugins/core.zip
David Ostrovskyaf719682016-09-28 20:31:18 +0200175----
176
177To build a specific plugin:
178
179----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700180 bazelisk build plugins/<name>
David Ostrovskyaf719682016-09-28 20:31:18 +0200181----
182
183The output JAR file will be be placed in:
184
185----
Luca Milanesio5bd7b9b2019-06-10 10:01:02 +0100186 bazel-bin/plugins/<name>/<name>.jar
David Ostrovskyaf719682016-09-28 20:31:18 +0200187----
188
189Note that when building an individual plugin, the `core.zip` package
190is not regenerated.
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200191
Han-Wen Nienhuys8ba8abe2016-10-25 15:54:28 +0200192[[IDEs]]
193== Using an IDE.
194
195=== IntelliJ
196
Marian Harbach34253372019-12-10 18:01:31 +0100197The Gerrit build works with Bazel's link:https://ij.bazel.build[IntelliJ plugin,role=external,window=_blank].
Alice Kober-Sotzekd9da89f2016-11-25 12:02:18 +0100198Please follow the instructions on <<dev-intellij#,IntelliJ Setup>>.
David Ostrovskyc69f3602016-11-13 08:01:08 -0800199
200=== Eclipse
201
202==== Generating the Eclipse Project
203
204Create the Eclipse project:
205
206----
David Pursehouse7e43d1d2017-01-24 08:45:16 +0900207 tools/eclipse/project.py
David Ostrovskyc69f3602016-11-13 08:01:08 -0800208----
209
210and then follow the link:dev-eclipse.html#setup[setup instructions].
211
212==== Refreshing the Classpath
213
214If an updated classpath is needed, the Eclipse project can be
215refreshed and missing dependency JARs can be downloaded by running
David Pursehouse7e43d1d2017-01-24 08:45:16 +0900216`project.py` again. For IntelliJ, you need to click the `Sync Project
Marian Harbach34253372019-12-10 18:01:31 +0100217with BUILD Files` button of link:https://ij.bazel.build[Bazel plugin,role=external,window=_blank].
David Ostrovskyc69f3602016-11-13 08:01:08 -0800218
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200219[[documentation]]
Nasser Grainawia55b20d2021-03-08 11:52:01 -0700220== Documentation
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200221
David Ostrovsky9413ff82016-10-25 00:02:17 +0200222To build only the documentation for testing or static hosting:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200223
David Ostrovsky9413ff82016-10-25 00:02:17 +0200224----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700225 bazelisk build Documentation:searchfree
David Ostrovsky9413ff82016-10-25 00:02:17 +0200226----
227
228The html files will be bundled into `searchfree.zip` in this location:
229
230----
231 bazel-bin/Documentation/searchfree.zip
232----
233
Luca Milanesiodcd5bbe2023-06-19 14:56:52 +0100234To use local fonts with the searchfree target:
235
236----
237 bazel build Documentation:searchfree_safe
238----
239
240The html files will be bundled into `searchfree.zip` or `searchfree_safe.zip` in this location:
241
242----
243 bazel-bin/Documentation/searchfree.zip
244 bazel-bin/Documentation/searchfree_safe.zip
245----
246
Antoine Musso8e4ae542020-12-22 12:09:16 +0100247To generate HTML files skipping the zip archiving:
248
249----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700250 bazelisk build Documentation
Antoine Musso8e4ae542020-12-22 12:09:16 +0100251----
252
253And open `bazel-bin/Documentation/index.html`.
254
255To build the Gerrit executable WAR with the documentation included:
David Ostrovsky9413ff82016-10-25 00:02:17 +0200256
257----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700258 bazelisk build withdocs
David Ostrovsky9413ff82016-10-25 00:02:17 +0200259----
260
261The WAR file will be placed in:
262
263----
264 bazel-bin/withdocs.war
265----
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200266
Antoine Musso524b0562020-11-18 10:36:05 +0100267Alternatively, one can generate the documentation as flat files:
268
269----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700270 bazelisk build Documentation:Documentation
Antoine Musso524b0562020-11-18 10:36:05 +0100271----
272
273The html, css, js files are placed in:
274
275----
276 `bazel-bin/Documentation/`
277----
278
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200279[[tests]]
280== Running Unit Tests
281
Clark Boylan8784a6c2023-09-27 16:35:19 -0700282Bazel BUILD files define test targets for Gerrit. You can run all declared
283test targets with:
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200284
285----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700286 bazelisk test --build_tests_only //...
Edwin Kempind31903c2016-11-14 17:01:44 -0800287----
288
Clark Boylan8784a6c2023-09-27 16:35:19 -0700289[[testgroups]]
290=== Running Test Groups
291
292To run one or more specific labeled groups of tests:
Edwin Kempind31903c2016-11-14 17:01:44 -0800293
294----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700295 bazelisk test --test_tag_filters=api,git //...
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200296----
297
Clark Boylan8784a6c2023-09-27 16:35:19 -0700298The following label values are currently supported for the group name:
David Pursehouse44445182017-02-22 15:59:17 +0900299
300* annotation
301* api
302* edit
303* git
David Pursehouse180bca52019-12-04 20:05:07 +0900304* git-protocol-v2
David Ostrovsky61a44ae2020-05-14 08:29:54 +0200305* git-upload-archive
David Pursehouse44445182017-02-22 15:59:17 +0900306* notedb
307* pgm
308* rest
309* server
310* ssh
311
Clark Boylan8784a6c2023-09-27 16:35:19 -0700312We can also select tests within a specific BUILD target group. For example
313`javatests/com/google/gerrit/acceptance/rest/account/BUILD` declares a
314rest_account test target group:
315
316----
317 bazelisk test //javatests/com/google/gerrit/acceptance/rest/account:rest_account
318----
319
320[[debugtests]]
321=== Debugging Tests
322
323To debug specific tests you will need to select the test target containing
324that test then use `--test_filter` to select the specific test you want.
325This `--test_filter` is a regex and can be used to select multiple tests
326out of the target:
327
328----
329 bazelisk test --test_output=streamed --test_filter=com.gerrit.TestClass.testMethod testTarget
330----
331
332For example `javatests/com/google/gerrit/acceptance/api/change/BUILD`
333defines a test target group for every `*IT.java` file in the directory.
334We can execute the single `getAmbiguous()` test found in ChangeIT.java using
335this `--test_filter` and target:
336
337----
338 bazelisk test --test_output=streamed \
339 --test_filter=com.google.gerrit.acceptance.api.change.ChangeIT.getAmbiguous \
340 //javatests/com/google/gerrit/acceptance/api/change:ChangeIT
341----
342
343[[additionaltestfiltering]]
344=== Additional Test Filtering
345
346To run only tests that do not use SSH:
347
348----
349 bazelisk test --test_env=GERRIT_USE_SSH=NO //...
350----
351
352To exclude tests that have been marked as flaky:
353
354----
355 bazelisk test --test_tag_filters=-flaky //...
356----
357
358To exclude tests that require very recent git client version:
359
360----
361 bazelisk test --test_tag_filters=-git-protocol-v2 //...
362----
363
364To run the tests against a specific index backend (LUCENE, FAKE):
365----
366 bazelisk test --test_env=GERRIT_INDEX_TYPE=LUCENE //...
367----
368
Nasser Grainawi02f53452021-02-19 08:17:49 -0700369Bazel itself supports a multitude of ways to
Clark Boylan8784a6c2023-09-27 16:35:19 -0700370link:https://bazel.build/run/build#specifying-build-targets[specify targets,role=external,window=_blank]
Nasser Grainawi02f53452021-02-19 08:17:49 -0700371for fine-grained test selection that can be combined with many of the examples
372above.
373
Clark Boylan8784a6c2023-09-27 16:35:19 -0700374[[testcaching]]
375=== Test Caching
376
377By default Bazel caches test results and will not reexecute tests unless they
378or their dependencies have been modified. To ignore cached test results and
379force the tests to rerun:
380
381----
382 bazelisk test --cache_test_results=NO //...
383----
384
385[[plugintests]]
386=== Running Plugin Tests
387
388Running tests for Gerrit plugins follows the process above. From within the
389Gerrit project root with the desired plugins checked out into `plugins/` we
390execute Bazel with the appropriate target:
391
392----
393 bazelisk test //plugins/replication/...
394----
395
Edwin Kempin08a0f272023-12-18 14:48:17 +0000396[[known-issues]]
397=== Known Issues
398
399[[byte-buddy-not-initialized-or-unavailable]]
400==== The Byte Buddy agent is not initialized or unavailable
401
402If running tests that make use of mocks fail with the exception below, set the
403`sandbox_tmpfs_path` flag for running tests in `.bazelrc` as described in this
404link:https://github.com/mockito/mockito/issues/1879#issuecomment-922459131[
405issue], e.g. add this line: `test --sandbox_tmpfs_path=/tmp`
406
407.Exception:
408----
409...
410Caused by: org.mockito.exceptions.base.MockitoInitializationException:
411Could not initialize inline Byte Buddy mock maker.
412
413It appears as if your JDK does not supply a working agent attachment mechanism.
414...
415Caused by: java.lang.IllegalStateException: The Byte Buddy agent is not initialized or unavailable
416at net.bytebuddy.agent.ByteBuddyAgent.getInstrumentation(ByteBuddyAgent.java:230)
417at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:617)
418at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:568)
419at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:545)
420at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<clinit>(InlineDelegateByteBuddyMockMaker.java:115)
421... 47 more
422----
423
Saša Živkov1b716dd2021-03-12 17:03:33 +0100424[[debugging-tests]]
425== Debugging Unit Tests
426In some cases it may be necessary to debug a test while running it in bazel. For example, when we
427observe a different test result in Eclipse and bazel. Using the `--java_debug` option will start the
428JVM in debug mode and await for a remote debugger to attach.
429
430Example:
431[source,bash]
432----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700433 bazelisk test --java_debug --test_tag_filters=delete-project //...
Saša Živkov1b716dd2021-03-12 17:03:33 +0100434 ...
435 Listening for transport dt_socket at address: 5005
436 ...
437----
438
439Now attach with a debugger to the port `5005`. For example use "Remote Java Application" launch
Martin Fick6b67d572023-04-04 14:23:14 -0600440configuration in Eclipse and specify the port `5005`.
Saša Živkov1b716dd2021-03-12 17:03:33 +0100441
David Ostrovsky17ef1272020-02-16 14:51:07 +0100442[[logging]]
443=== Controlling logging level
Hamza Kacedc54e6b52020-01-24 12:59:09 -0500444
David Ostrovsky17ef1272020-02-16 14:51:07 +0100445Per default, logging level is set to `INFO` level for all tests. The `DEBUG`
446log level can be enabled for the tests.
Hamza Kacedc54e6b52020-01-24 12:59:09 -0500447
David Ostrovsky17ef1272020-02-16 14:51:07 +0100448In IDE, set `-Dgerrit.logLevel=debug` as a VM argument. With `bazel`, pass
449`GERRIT_LOG_LEVEL=debug` environment variable:
Hamza Kacedc54e6b52020-01-24 12:59:09 -0500450
451----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700452 bazelisk test --test_filter=com.google.gerrit.server.notedb.ChangeNotesTest \
453 --test_env=GERRIT_LOG_LEVEL=debug \
454 javatests/com/google/gerrit/server:server_tests
Hamza Kacedc54e6b52020-01-24 12:59:09 -0500455----
456
David Ostrovsky17ef1272020-02-16 14:51:07 +0100457The log results can be found in:
458`bazel-testlogs/javatests/com/google/gerrit/server/server_tests/test.log`.
459
460
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200461== Dependencies
462
Han-Wen Nienhuys314fb112016-11-14 10:04:02 -0800463Dependency JARs are normally downloaded as needed, but you can
464download everything upfront. This is useful to enable
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200465subsequent builds to run without network access:
466
467----
Clark Boylan8784a6c2023-09-27 16:35:19 -0700468 bazelisk fetch //...
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200469----
470
471When downloading from behind a proxy (which is common in some corporate
472environments), it might be necessary to explicitly specify the proxy that
473is then used by `curl`:
474
475----
476 export http_proxy=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>
477----
478
David Ostrovskyc0f6d4d2017-01-20 08:30:07 +0100479Redirection to local mirrors of Maven Central and the Gerrit storage
480bucket is supported by defining specific properties in
481`local.properties`, a file that is not tracked by Git:
482
483----
484 echo download.GERRIT = http://nexus.my-company.com/ >>local.properties
485 echo download.MAVEN_CENTRAL = http://nexus.my-company.com/ >>local.properties
486----
487
488The `local.properties` file may be placed in the root of the gerrit repository
489being built, or in `~/.gerritcodereview/`. The file in the root of the gerrit
490repository has precedence.
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200491
492== Building against unpublished Maven JARs
493
Dave Borowitz8626f872019-04-19 14:34:36 -0700494To build against unpublished Maven JARs, like PrologCafe, the custom JARs must
495be installed in the local Maven repository (`mvn clean install`) and
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200496`maven_jar()` must be updated to point to the `MAVEN_LOCAL` Maven repository for
497that artifact:
498
499[source,python]
500----
501 maven_jar(
Dave Borowitz8626f872019-04-19 14:34:36 -0700502 name = 'prolog-runtime',
503 artifact = 'com.googlecode.prolog-cafe:prolog-runtime:42',
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200504 repository = MAVEN_LOCAL,
505 )
506----
507
508== Building against artifacts from custom Maven repositories
509
510To build against custom Maven repositories, two modes of operations are
511supported: with rewrite in local.properties and without.
512
513Without rewrite the URL of custom Maven repository can be directly passed
514to the maven_jar() function:
515
516[source,python]
517----
518 GERRIT_FORGE = 'http://gerritforge.com/snapshot'
519
520 maven_jar(
521 name = 'gitblit',
Paladox nonedab92ab2017-01-28 22:56:33 +0000522 artifact = 'com.gitblit:gitblit:1.4.0',
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200523 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200524 repository = GERRIT_FORGE,
525 )
526----
527
528When the custom URL has to be rewritten, then the same logic as with Gerrit
529known Maven repository is used: Repo name must be defined that matches an entry
530in local.properties file:
531
532----
533 download.GERRIT_FORGE = http://my.company.mirror/gerrit-forge
534----
535
536And corresponding WORKSPACE excerpt:
537
538[source,python]
539----
540 GERRIT_FORGE = 'GERRIT_FORGE:'
541
542 maven_jar(
543 name = 'gitblit',
Paladox nonedab92ab2017-01-28 22:56:33 +0000544 artifact = 'com.gitblit:gitblit:1.4.0',
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200545 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200546 repository = GERRIT_FORGE,
547 )
548----
549
David Ostrovskyad61c852019-01-14 07:11:04 +0100550== Building against SNAPSHOT Maven JARs
551
552To build against SNAPSHOT Maven JARs, the complete SNAPSHOT version must be used:
553
554[source,python]
555----
556 maven_jar(
557 name = "pac4j-core",
558 artifact = "org.pac4j:pac4j-core:3.5.0-SNAPSHOT-20190112.120241-16",
559 sha1 = "da2b1cb68a8f87bfd40813179abd368de9f3a746",
560 )
561----
562
David Ostrovsky2bf355d2018-05-30 08:58:22 +0200563[[bazel-local-caches]]
David Ostrovsky88bc3722017-09-19 08:29:27 +0200564
David Pursehouse42cb2932018-06-05 14:49:06 +0900565To accelerate builds, several caches are activated per default:
David Ostrovsky2bf355d2018-05-30 08:58:22 +0200566
567* ~/.gerritcodereview/bazel-cache/downloaded-artifacts
568* ~/.gerritcodereview/bazel-cache/repository
569* ~/.gerritcodereview/bazel-cache/cas
570
Antoine Mussoff89f792021-05-04 11:14:05 +0200571The `downloaded-artifacts` cache can be relocated by setting the
572`GERRIT_CACHE_HOME` environment variable. The other two can be adjusted with
Clark Boylan8784a6c2023-09-27 16:35:19 -0700573`bazelisk build` options `--repository_cache` and `--disk_cache` respectively.
Antoine Mussoff89f792021-05-04 11:14:05 +0200574
David Pursehouse42cb2932018-06-05 14:49:06 +0900575Currently none of these caches have a maximum size limit. See
Marian Harbach34253372019-12-10 18:01:31 +0100576link:https://github.com/bazelbuild/bazel/issues/5139[this bazel issue,role=external,window=_blank] for
David Pursehouse42cb2932018-06-05 14:49:06 +0900577details. Users should watch the cache sizes and clean them manually if
578necessary.
579
Dave Borowitzf04eb082018-07-16 08:51:17 -0700580[[npm-binary]]
581== NPM Binaries
582
Ben Rohlfsda0a62b2021-04-26 17:02:19 +0200583Parts of the Gerrit web app build require running NPM-based JavaScript programs
584as "binaries". We don't attempt to resolve and download NPM dependencies at
585build time, but instead use pre-built bundles of the NPM binary along with all
586its dependencies. Some packages on
Marian Harbach34253372019-12-10 18:01:31 +0100587link:https://docs.npmjs.com/misc/registry[registry.npmjs.org,role=external,window=_blank] come with their
Dave Borowitzf04eb082018-07-16 08:51:17 -0700588dependencies bundled, but this is the exception rather than the rule. More
589commonly, to add a new binary to this list, you will need to bundle the binary
590yourself.
591
592[NOTE]
593We can only use binaries that meet certain licensing requirements, and that do
594not include any native code.
595
596Start by checking that the license and file types of the bundle are acceptable:
597[source,bash]
598----
599 gerrit_repo=/path/to/gerrit
600 package=some-npm-package
601 version=1.2.3
602
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100603 # Note - yarn must be installed before running the following commands
604 yarn global add license-checker && \
Dave Borowitzf04eb082018-07-16 08:51:17 -0700605 rm -rf /tmp/$package-$version && mkdir -p /tmp/$package-$version && \
606 cd /tmp/$package-$version && \
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100607 yarn add $package@$version && \
Dave Borowitzf04eb082018-07-16 08:51:17 -0700608 license-checker | grep licenses: | sort -u
609----
610
611This will output a list of the different licenses used by the package and all
612its transitive dependencies. We can only legally distribute a bundle via our
613storage bucket if the licenses allow us to do so. As long as all of the listed
614license are allowed by
615link:https://opensource.google.com/docs/thirdparty/licenses/[Google's
Marian Harbach34253372019-12-10 18:01:31 +0100616standards,role=external,window=_blank]. Any `by_exception_only`, commercial, prohibited, or unlisted
Dave Borowitzf04eb082018-07-16 08:51:17 -0700617licenses are not allowed; otherwise, it is ok to distribute the source. If in
618doubt, contact a maintainer who is a Googler.
619
620Next, check the file types:
621[source,bash]
622----
623 cd /tmp/$package-$version
624 find . -type f | xargs file | grep -v 'ASCII\|UTF-8\|empty$'
625----
626
627If you see anything that looks like a native library or binary, then we can't
628use the bundle.
629
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100630If everything looks good, install the package with the following command:
631[source, bash]
Dave Borowitzf04eb082018-07-16 08:51:17 -0700632----
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100633# Add to ui_npm. Other packages.json can be updated in the same way
634cd $gerrit_repo/polygerrit-ui/app
Clark Boylan8784a6c2023-09-27 16:35:19 -0700635bazelisk run @nodejs//:yarn add $package
Dave Borowitzf04eb082018-07-16 08:51:17 -0700636----
637
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100638Update the `polygerrit-ui/app/node_modules_licenses/licenses.ts` file. You should add licenses
Martin Fick6b67d572023-04-04 14:23:14 -0600639for the package itself and for all transitive dependencies. If you forgot to add a license, the
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100640`Documentation:check_licenses` test will fail.
Dave Borowitzf04eb082018-07-16 08:51:17 -0700641
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100642After the update, commit all changes to the repository (including `yarn.lock`).
Dave Borowitzf04eb082018-07-16 08:51:17 -0700643
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100644[NOTE]
645====
646If a npm package has transitive dependencies (or just several files) with a not allowed
647license and you can't avoid use it in release, then you can add this package.
648For example some packages contain demo-code with a different license. Another example - optional
Ben Rohlfsda0a62b2021-04-26 17:02:19 +0200649dependencies, which are not needed to build the Gerrit web app, but they are installed together
650with the package anyway.
Dave Borowitzf04eb082018-07-16 08:51:17 -0700651
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100652In this case you should exclude all files and/or transitive dependencies with a not allowed license.
653Adding such package requires additional updates:
Dave Borowitzf04eb082018-07-16 08:51:17 -0700654
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100655- Add dependencies (or files) to the license.ts with an appropriate license marked with
656`allowed: false`.
Dave Borowitzf04eb082018-07-16 08:51:17 -0700657
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100658- update package.json postinstall script to remove all non-allowed files (if you don't
659update postinstall script, `Documentation:check_licenses` test will fail.)
660====
661
662=== Update NPM Binaries
663To update a NPM binary the same actions as for a new one must be done (check licenses,
664update `licenses.ts` file, etc...). The only difference is a command to install a package: instead
Clark Boylan8784a6c2023-09-27 16:35:19 -0700665of `bazelisk run @nodejs//:yarn add $package` you should run the `bazelisk run @nodejs//:yarn upgrade ...`
Dmitrii Filippovc2cdcce2020-01-27 12:57:42 +0100666command with correct arguments. You can find the list of arguments in the
667link:https://classic.yarnpkg.com/en/docs/cli/upgrade/[yarn upgrade doc,role=external,window=_blank].
Dave Borowitzf04eb082018-07-16 08:51:17 -0700668
669
Han-Wen Nienhuys9c15e2b2019-05-16 16:59:33 +0200670[[RBE]]
David Pursehouse0713b9a2019-05-21 12:20:26 +0900671== Google Remote Build Support
Han-Wen Nienhuys9c15e2b2019-05-16 16:59:33 +0200672
673The Bazel build can be used with Google's Remote Build Execution.
674
675
676This needs the following setup steps:
677
678```
679gcloud auth application-default login
680gcloud services enable remotebuildexecution.googleapis.com --project=${PROJECT}
681```
682
683Create a worker pool. The instances should have at least 4 CPUs each
684for adequate performance.
685
686```
687gcloud alpha remote-build-execution worker-pools create default \
688 --project=${PROJECT} \
689 --instance=default_instance \
690 --worker-count=50 \
Han-Wen Nienhuys8abed332020-04-06 16:50:38 +0200691 --machine-type=e2-standard-4 \
Han-Wen Nienhuys9c15e2b2019-05-16 16:59:33 +0200692 --disk-size=200
693```
694
David Ostrovskybb951632023-11-14 06:40:36 +0100695Note, that we are using Ubuntu2204 docker image from bazel project:
David Ostrovsky65951c52020-03-28 18:23:20 +0100696
David Ostrovsky65951c52020-03-28 18:23:20 +0100697
698```
David Ostrovskybb951632023-11-14 06:40:36 +0100699docker pull gcr.io/bazel-public/ubuntu2204-java17@sha256:ffe37746a34537d8e73cef5a20ccd3a4e3ec7af3e7410cba87387ba97c0e520f
David Ostrovsky65951c52020-03-28 18:23:20 +0100700```
701
David Ostrovskybb951632023-11-14 06:40:36 +0100702Re-build rbe_autoconfig project, conduct a new release and switch to using it
703in `WORKSPACE` file. For more details see this
704link:https://github.com/davido/rbe_autoconfig[repository,role=external,window=_blank]
David Ostrovsky65951c52020-03-28 18:23:20 +0100705
706Note, to authenticate to the gcr.io registry, the following command must be
707used:
708
709```
710gcloud auth configure-docker
711```
712
713To see the documentation, developer must be added to this group:
714https://groups.google.com/forum/#!forum/rbe-alpha-customers.
715
716Documentation can be found at:
717https://cloud.google.com/remote-build-execution/docs.
718
Han-Wen Nienhuys9c15e2b2019-05-16 16:59:33 +0200719To use RBE, execute
720
721```
Clark Boylan8784a6c2023-09-27 16:35:19 -0700722bazelisk test --config=remote \
Han-Wen Nienhuys9c15e2b2019-05-16 16:59:33 +0200723 --remote_instance_name=projects/${PROJECT}/instances/default_instance \
724 javatests/...
725```
726
727
Alvaro Vilaplana Garciad0908c92023-11-15 15:59:25 +0000728== BuildBuddy Remote Build Support
729
730To utilize the BuildBuddy Remote Build Execution service, please consult the
731documentation available at the following link: https://www.buildbuddy.io[BuildBuddy].
732
733To use RBE, execute
734
735```
736bazelisk test --config=remote_bb \
737 --remote_instance_name=projects/${PROJECT}/instances/default_instance \
738 --remote_header=x-buildbuddy-api-key=YOUR_API_KEY \
739 javatests/...
740```
741
742
Han-Wen Nienhuys80fcbe12016-09-22 13:16:51 +0200743GERRIT
744------
745Part of link:index.html[Gerrit Code Review]
746
747SEARCHBOX
748---------