|
| 1 | +# Monorepo Scoped Development Guide |
| 2 | + |
| 3 | +This document outlines development workflows and build strategies when working with specific client libraries or modules in the `google-cloud-java` monorepo. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Building a Specific Service (Fast Reactor Builds) |
| 8 | + |
| 9 | +Instead of running a full build of the entire monorepo (which contains over 250+ modules and can take up to 30 minutes), you can target a single client library and let Maven automatically resolve and build all of its upstream dependencies using the `-pl` (project list) and `-am` (also make) flags. |
| 10 | + |
| 11 | +Run the following command from the **root directory** of the repository: |
| 12 | + |
| 13 | +```bash |
| 14 | +mvn install -pl java-spanner/google-cloud-spanner -am -P quick-build -DskipTests |
| 15 | +``` |
| 16 | + |
| 17 | +### Flag Explanations: |
| 18 | +* **`-pl <module-path>`**: Targets only the specified project module. |
| 19 | +* **`-am` (Also Make)**: Tells Maven to analyze the dependency tree and automatically compile any projects in the reactor that the target library depends on (e.g., `gax-java`, `google-auth-library-java`, `google-cloud-core`). |
| 20 | +* **`-P quick-build`**: Bypasses unnecessary verification checks (like Checkstyle, Enforcer, Animal Sniffer) to significantly speed up local iteration. |
| 21 | +* **`-DskipTests`**: Skips running unit and integration tests during compilation. |
| 22 | + |
| 23 | +### Edge Case: Imported BOMs in `<dependencyManagement>` |
| 24 | + |
| 25 | +> [!WARNING] |
| 26 | +> **Maven's `-am` (Also Make) reactor analysis does not automatically build imported BOMs.** |
| 27 | +
|
| 28 | +#### The Problem: |
| 29 | +If a module (or one of its parent dependencies/dependency BOMs) imports another BOM from within the same monorepo via `<scope>import</scope>` in a `<dependencyManagement>` block, Maven **does not** recognize it as a concrete build dependency. |
| 30 | +* *Example:* `google-cloud-bigtable-deps-bom` imports `google-cloud-monitoring-bom` via `<dependencyManagement>`. |
| 31 | +* Running `mvn install -pl java-bigtable/google-cloud-bigtable -am` (or targeting the deps-bom directly) will **succeed without actually building the local version of `google-cloud-monitoring-bom`**. |
| 32 | + |
| 33 | +#### The Solution (Targeted Build): |
| 34 | +To resolve this without doing a full 30-minute monorepo build, you can explicitly list the imported BOMs in the `-pl` parameter: |
| 35 | + |
| 36 | +```bash |
| 37 | +mvn install -pl java-monitoring/google-cloud-monitoring-bom,java-bigtable/google-cloud-bigtable-deps-bom,java-bigtable/google-cloud-bigtable -am -P quick-build -DskipTests |
| 38 | +``` |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## 2. Building All Submodules under a Service Directory |
| 43 | + |
| 44 | +Many services in this repository (e.g., `java-spanner`, `java-bigtable`) are structured as aggregator parents with multiple submodules (e.g., separate directories for client code, gRPC/Protobuf stubs, executors, and BOMs). |
| 45 | + |
| 46 | +Once your upstream monorepo dependencies are installed in your local ~/.m2/repository cache, you can run standard Maven commands for a specific service from the repository root using the -pl flag: |
| 47 | + |
| 48 | +```bash |
| 49 | +cd java-spanner |
| 50 | +mvn compile |
| 51 | +``` |
| 52 | + |
| 53 | +Your IDE such as Intellij should also be able to import all the upstream dependencies at this moment. You can perform the same operations as you would in a normal project such as running unit tests, debugging and so on. |
0 commit comments