You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: General guidance on Java development practices, building, testing, and style in the monorepo. Use this skill when working on Java code across the repository.
3
+
description: Workflow guidance for performing Java development tasks in this repository.
4
4
---
5
5
6
-
# Java Development Guide
6
+
# Java Development Workflow
7
7
8
-
This skill provides general guidelines for Java development inside the monorepo. It covers building, formatting, testing, and style conventions to ensure consistency across modules.
8
+
Use this skill when tasked with modifying Java code, fixing bugs, or adding features. It guides you through the typical development lifecycle in this repo.
9
9
10
-
## Workflow
10
+
## Workflow Steps
11
11
12
-
### 1. Building the Project
12
+
### Step 1: Understand the Scope
13
+
- Determine if you are working on **Core Components** (`sdk-platform-java`) or a specific **Client Library** (`java-<service>`).
14
+
- Review the root [AGENTS.md](../../AGENTS.md) for the Style Guide and Dependency Management rules that apply repo-wide.
13
15
14
-
The repository uses Maven as its primary build system.
16
+
### Step 2: Make Changes and Build
17
+
- Apply your code changes.
18
+
- To build efficiently, use the recommended flags or scoped builds detailed in [AGENTS.md](../../AGENTS.md#building-the-project).
15
19
16
-
***Build All Modules**: To build all modules from the root of the repository, run:
17
-
```bash
18
-
mvn install -T 1C -P quick-build
19
-
```
20
-
> [!TIP]
21
-
> Use `-T 1C` to build modules in parallel (one thread per CPU core) and `-P quick-build` to skip unnecessary plugins for faster builds.
22
-
***Build a Specific Module**: You can also run Maven commands within a specific module directory (e.g., `java-bigquery`) to build only that module.
20
+
### Step 3: Determine and Run Tests
21
+
- If working on a **Client Library**, run its unit tests (`mvn test` in the module directory) and check its README for integration test procedures.
22
+
- If working on **Core Components** (`sdk-platform-java`), you **must** follow the testing heuristics in [sdk-platform-java/DEVELOPMENT.md](../../../sdk-platform-java/DEVELOPMENT.md#testing-guide) to know which tests are required.
23
+
- If golden files need updating, follow the specific procedures referenced in [AGENTS.md](../../AGENTS.md#specialized-development-guides).
23
24
24
-
### 2. Code Formatting
25
+
### Step 4: Format Code
26
+
- You **must** ensure the code is formatted before completing a task. Use the formatting commands listed in [AGENTS.md](../../AGENTS.md#code-formatting).
25
27
26
-
Code formatting is enforced using the `fmt-maven-plugin`.
27
-
28
-
***Check Formatting**: To check for formatting issues without modifying files, run:
29
-
```bash
30
-
mvn fmt:check -T 1C
31
-
```
32
-
***Apply Formatting**: To automatically format the code according to the project style, run:
33
-
```bash
34
-
mvn fmt:format -T 1C
35
-
```
36
-
> [!TIP]
37
-
> To save time, run `mvn fmt:format` within the specific module directory you are working on, rather than at the root.
38
-
> [!NOTE]
39
-
> Always run `mvn fmt:format` before committing changes to avoid build failures due to formatting.
40
-
41
-
### 3. Testing Strategy
42
-
43
-
***Unit Tests**: Traditional unit tests should be added for individual classes and methods. Run them using:
44
-
```bash
45
-
mvn test -T 1C
46
-
```
47
-
***Integration Tests**: Many modules have integration tests that run against live services or emulators. These may require specific profiles or environment variables. Refer to the specific module's README for details.
48
-
49
-
### 4. Style Guide
50
-
51
-
Follow these general rules to maintain code quality and consistency:
52
-
53
-
1. **Minimize Visibility**: Default to the most restrictive access level possible. Avoid using `public` unless the class or method is intended to be part of the public API.
54
-
2. Avoid Fully Qualified Names: Use imports to keep class names short and readable, rather than using fully qualified names in the code.
55
-
3. **Avoid Obsolete APIs**: Do not call methods marked with `@ObsoleteApi` or `@Deprecated` unless there are no viable alternatives.
56
-
4. **Clean Diffs**: Avoid unnecessary formatting changes or whitespace modifications to keep diffs clean and easy to review.
57
-
58
-
### 5. Dependency Management
59
-
60
-
* **Version Bumps**: Try not to bump any external dependency versions unless there is a known security vulnerability (CVE) or a critical bug fix.
61
-
* **New Dependencies**: Avoid introducing new external dependencies. If a new dependency is required, provide a strong justification in the pull request.
62
-
* **Standard Library First**: Prefer to use features from the Java standard library, followed by existing dependencies in the project (preferably Google-managed dependencies).
63
-
64
-
### 6. Contribution Guidelines
65
-
66
-
* **Commit Messages**: Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. Include the module as the scope (e.g., `feat(spanner): ...`, `fix(bigquery): ...`).
67
-
* **Pull Requests**: All code changes must be submitted via a pull request and require review. Ensure you pull the latest changes from `main` and resolve any conflicts before submitting.
28
+
### Step 5: Verify and Document
29
+
- Verify that all tests pass and formatting is correct.
30
+
- Follow the Contribution Guidelines in [AGENTS.md](../../AGENTS.md#7-contribution-guidelines) for creating commits and PRs.
Copy file name to clipboardExpand all lines: sdk-platform-java/GEMINI.md
+9-111Lines changed: 9 additions & 111 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
3
3
## 1. Overview
4
4
5
-
This directory, sdk-platform-java, contains the foundational components for building Java client libraries for Google Cloud Platform services. It includes the GAPIC (Generated API Client) generator for Java, the GAX (Google API Extensions) runtime library, and other shared modules.
5
+
This directory, `sdk-platform-java`, contains the foundational components for building Java client libraries for Google Cloud Platform services. It includes the GAPIC (Generated API Client) generator for Java, the GAX (Google API Extensions) runtime library, and other shared modules.
6
+
7
+
For general project rules, style guides, dependency management, and contribution guidelines, please refer to the root [AGENTS.md](../AGENTS.md).
6
8
7
9
## 2. Project Structure
8
10
@@ -28,130 +30,26 @@ The repository is structured into several key modules:
28
30
29
31
***`java-shared-dependencies`**: Manages shared Maven dependencies for all Google Cloud Java client libraries. This ensures consistency and helps avoid dependency conflicts.
30
32
31
-
## 3. Getting Started
32
-
33
-
### 3.1. Prerequisites
34
-
35
-
To build and work with this project, you will need to install:
36
-
37
-
* Java 11+
38
-
* Maven
39
-
40
-
### 3.2. Building the Project
41
-
42
-
The project uses Maven for its primary build system. To build all modules, run the following command from the root of the repository:
43
-
44
-
```sh
45
-
mvn install
46
-
```
47
-
48
-
### 3.3. Code Formatting
49
-
50
-
Code formatting is enforced using the `fmt-maven-plugin`. To check for formatting issues, run:
51
-
52
-
```sh
53
-
mvn fmt:check
54
-
```
55
-
56
-
To format the code, run:
57
-
58
-
```sh
59
-
mvn fmt:format
60
-
```
61
-
62
-
## 4. Testing
63
-
64
-
### 4.1. Testing Strategy
65
-
66
-
The repository employs a multi-layered testing strategy to ensure the quality and correctness of the generated code:
67
-
68
-
***Unit Tests:** Traditional unit tests for individual classes and methods. See [unit testing best practices](https://engdoc.corp.google.com/eng/doc/devguide/testing/unit/best-practices.md?cl=head&polyglot=java).
69
-
***Golden Unit Tests:** These tests generate code from test protos and compare the output to "golden" files, which are pre-approved versions of the generated code. These test cases exist inside the `gapic-generator-java` module. See [GrpcServiceStubClassComposerTest](https://github.com/googleapis/google-cloud-java/blob/main/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java) for an example of golden unit tests. The steps for golden unit tests include creating a test proto, loading the test proto, generating from the test proto, and comparing the result with a golden file.
70
-
***Showcase Integration Tests:** These tests run the generated Showcase client against a local Showcase server to verify end-to-end functionality. This is the preferred way of testing integration tests.
71
-
***Golden Integration Tests:** These tests generate full client libraries for real Google Cloud APIs and compare them to golden versions. This is an older test strategy and showcase testing is preferred.
33
+
## 3. Testing
72
34
73
-
Based on where the code changes are, we should add different tests, in general
35
+
For detailed testing strategy and heuristics on which tests to run based on code changes, please refer to [DEVELOPMENT.md](DEVELOPMENT.md).
74
36
75
-
* If the changes are in `gax` or `api-common` only, you _must_ add traditional unit tests, you _may_ add showcase integration tests if you are modifying a public setting.
76
-
* If the changes are in `gapic-generator-java` only, showcase integration tests are most likely not needed
77
-
* If they are in the `composer` module, you _must_ add golden unit tests, you _may_ add traditional unit tests for better coverage and easier testing.
78
-
* If they are in the `parser` module, you _should_ add traditional unit tests with a test proto if possible, you _may_ add golden unit tests to easily see the changes. For example, [routing_rule_parser_testing](https://github.com/googleapis/google-cloud-java/blob/main/sdk-platform-java/gapic-generator-java/src/test/proto/routing_rule_parser_testing.proto) that is only used for testing [RoutingRuleParser](https://github.com/googleapis/google-cloud-java/blob/main/sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/RoutingRuleParser.java).
79
-
* If they are in `other modules(ast, model, writer etc.)`, you _must_ add traditional unit tests, you _may_ add golden unit tests to easily see the changes.
80
-
- If the changes are in both `gax` and `gapic-generator-java`, you _must_ add all test layers, including traditional unit tests, golden unit tests and showcase integration tests.
81
-
82
-
### 4.2. Running Unit Tests
37
+
### 3.1. Running Unit Tests
83
38
84
39
Unit tests can be tested via this command:
85
40
86
41
```sh
87
42
mvn test
88
43
```
89
44
90
-
### 4.3. Running Golden Integration Tests
45
+
### 3.2. Running Golden Integration Tests
91
46
92
47
Golden integration tests are run using Bazel. To run all golden integration tests, use the following command from the root of the repository:
93
48
94
49
```sh
95
50
bazelisk test //...
96
51
```
97
52
98
-
Specific integration tests can be run by specifying the target, for example:
99
-
100
-
```sh
101
-
bazelisk test //test/integration:redis
102
-
```
103
-
104
-
### 4.4. Updating Golden Files
105
-
106
-
If you make changes that affect the generated code, you will need to update the golden files. This can be done using the following command:
107
-
108
-
```sh
109
-
bazelisk run //test/integration:update_asset && bazelisk run //test/integration:update_credentials && bazelisk run //test/integration:update_iam && bazelisk run //test/integration:update_kms && bazelisk run //test/integration:update_pubsub && bazelisk run //test/integration:update_logging && bazelisk run //test/integration:update_redis && bazelisk run //test/integration:update_storage && bazelisk run //test/integration:update_library && bazelisk run //test/integration:update_compute && bazelisk run //test/integration:update_bigtable && bazelisk run //test/integration:update_apigeeconnect
110
-
```
111
-
112
-
### 4.5. Running Showcase Integration Tests
113
-
114
-
Showcase integration tests are run against a local server that implements the Showcase API. The `java-showcase/README.md` file provides detailed instructions on how to run these tests. The general steps are:
115
-
116
-
1.**Install the Showcase server:**
117
-
118
-
```sh
119
-
go install github.com/googleapis/gapic-showcase/cmd/gapic-showcase@latest
120
-
```
121
-
122
-
2. **Run the Showcase server:**
123
-
124
-
```sh
125
-
gapic-showcase run
126
-
```
127
-
128
-
3. **Run the integration tests:**
129
-
130
-
```sh
131
-
cd java-showcase
132
-
mvn verify -P enable-integration-tests
133
-
```
134
-
135
-
## 5. Style Guide
136
-
137
-
1. Minimize visibility scopes by defaulting to the most restrictive access level, avoiding the `public` modifier unless required.
138
-
2. Use short names over fully qualified names.
139
-
3. Avoid calling `@ObsoleteApi` or `@Deprecated` methods unless there are no alternatives.
140
-
4. Avoid unnecessary formatting changes to keep diffs clean.
141
-
5. Use `mvn`for everything other than the `test/integration` folder.
142
-
143
-
## 6. Dependency Management
144
-
145
-
- Try not to bump any external dependency version unless there is a known CVE (security or vulnerability issue) or a critical bug fix.
146
-
- Try to avoid introducing new external dependencies. If a new dependency is required, please state the reason.
147
-
- Prefer to use features from the Java standard library, then try to use features from any existing dependencies (preferably from Google managed dependencies).
148
-
149
-
## 7. Contribution Guidelines
53
+
### 3.3. Running Showcase Integration Tests
150
54
151
-
- **Commits:** Commit messages should follow the [Conventional Commits](https://www.conventionalcommits.org/)
152
-
specification. The format is `<type>: <description>`. The type should be one of the following: fix, feat,
153
-
build, chore, docs, test, or refactor.
154
-
- **Issues:** All significant changes should start with a GitHub issue.
155
-
- **Pull Requests:** All code changes must be submitted via a pull request and require review. Before creating a PR, always pull latest from main, merge main to local branch and resolve any conflicts.
156
-
- **Testing:** All new logic should be accompanied by tests.
157
-
- For more details, see `CONTRIBUTING.md`.
55
+
Showcase integration tests are run against a local server that implements the Showcase API. The `java-showcase/README.md` file provides detailed instructions on how to run these tests.
0 commit comments