|
| 1 | +# Java SDK Generation Pipeline Troubleshooting Guide |
| 2 | + |
| 3 | +This guide helps you **identify which category** a pipeline failure belongs to and **apply the solution**. |
| 4 | + |
| 5 | +> Applies to: **Java SDK generation pipeline** (spec PR validation / spec PR generation) |
| 6 | +
|
| 7 | +- [Quick Triage](#quick-triage) |
| 8 | +- [tspconfig.yaml Errors](#1-tspconfig-errors) — misconfigurations in the spec repo's `tspconfig.yaml` |
| 9 | +- [Customization Errors](#2-customization-errors) — hand-written SDK code conflicts with regenerated code |
| 10 | +- [Intermittent Errors](#3-intermittent-errors) — transient failures, usually resolved by rerun |
| 11 | +- [Escalation](#escalation) |
| 12 | + |
| 13 | +> Related: [SDK Validation FAQ](https://aka.ms/azsdk/sdk-automation-faq) | [SDK Generation Pipelines](https://eng.ms/docs/products/azure-developer-experience/develop/sdk-generation-pipelines) | [SDK Release Pipeline](https://eng.ms/docs/products/azure-developer-experience/develop/sdk-release/sdk-release-pipeline) | [Language - Java Teams channel][teams-java] |
| 14 | +
|
| 15 | +--- |
| 16 | + |
| 17 | +## Quick Triage |
| 18 | + |
| 19 | +Find the most specific signal in the failure log and jump directly: |
| 20 | + |
| 21 | +| Log Signal | Category | Jump | |
| 22 | +|---|---|---| |
| 23 | +| `[COMPILE] Maven build fail.` + Checkstyle `PackageName` `must match pattern` | tspconfig | [1.1 Namespace Segment Too Long](#11-namespace-segment-too-long) | |
| 24 | +| `not supported by Fluent Premium` | tspconfig | [1.2 Unsupported Emitter Option (Fluent Premium)](#12-unsupported-emitter-option-fluent-premium) | |
| 25 | +| Verify Swagger and TypeSpec Code Generation check fails | tspconfig | [1.3 Verify Swagger and TypeSpec Code Generation fails](#13-verify-swagger-and-typespec-code-generation-fails) | |
| 26 | +| `[COMPILE] Maven build fail.` + customization class/method referenced | customization | [2. Customization Errors](#2-customization-errors) | |
| 27 | +| `Could not resolve dependencies` / `Could not transfer artifact` | intermittent | [3.1 Maven Dependency Download Failure](#31-maven-dependency-download-failure) | |
| 28 | +| None match | unknown | [Escalation](#escalation) | |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 1. tspconfig Errors |
| 33 | + |
| 34 | +**How to identify:** The error message contains `[VALIDATE][tspconfig.yaml]` or `[GENERATE] ...`, or generation output lands in the wrong directory. |
| 35 | + |
| 36 | +**References:** |
| 37 | +- TypeSpec configuration (tspconfig): https://typespec.io/docs/handbook/configuration/configuration/ |
| 38 | +- Azure TypeSpec Autorest emitter reference: https://azure.github.io/typespec-azure/docs/emitters/typespec-autorest/reference/emitter/ |
| 39 | +- Azure TypeSpec Java emitter reference: https://azure.github.io/typespec-azure/docs/emitters/clients/typespec-java/reference/emitter/ |
| 40 | + |
| 41 | +### 1.1 Namespace Segment Too Long |
| 42 | + |
| 43 | +**Log signal:** |
| 44 | +- `[COMPILE] Maven build fail.` |
| 45 | +- Checkstyle `PackageName` error with `must match pattern` |
| 46 | + |
| 47 | +**Error (real-world example):** |
| 48 | +``` |
| 49 | +[ERROR] Name 'com.azure.resourcemanager.<verylongsegment>...' must match pattern |
| 50 | +'^(?=.{9,80}$)((com.microsoft|com.azure)(\.[a-z][a-z0-9]{1,31})*)+$'. [PackageName] |
| 51 | +[ERROR] Failed to execute goal ... maven-checkstyle-plugin ... There are N errors reported by Checkstyle |
| 52 | +``` |
| 53 | + |
| 54 | +**Root cause:** The namespace does not match the repository's Checkstyle `PackageName` rule. |
| 55 | + |
| 56 | +**Solution:** |
| 57 | + |
| 58 | +1. **Check whether the namespace is approved.** If the long namespace has been reviewed and approved (e.g. it matches the service name exactly): |
| 59 | + - Add a Checkstyle suppression to [`eng/lintingconfigs/checkstyle/track2/checkstyle-suppressions.xml`](https://github.com/Azure/azure-sdk-for-java/blob/main/eng/lintingconfigs/checkstyle/track2/checkstyle-suppressions.xml#L109-L110). For example: |
| 60 | + ```xml |
| 61 | + <!-- Suppress the long package name in yourservice --> |
| 62 | + <suppress checks="PackageName" files="com.azure.resourcemanager.yourverylongservicename.*" /> |
| 63 | + ``` |
| 64 | +2. **If the namespace is not approved**, rename or shorten the namespace until it matches the `PackageName` rule shown in the error log. In practice, check the generated package name against the regex and reduce any part of the namespace that causes the mismatch, such as an overly long segment or an overall package name that is too long. |
| 65 | + |
| 66 | +### 1.2 Unsupported Emitter Option (Fluent Premium) |
| 67 | + |
| 68 | +**Log signal:** |
| 69 | +- `not supported by Fluent Premium` |
| 70 | + |
| 71 | +**Error (real-world example):** |
| 72 | +``` |
| 73 | +error @azure-tools/typespec-java/generator-error: ... - Unhandled error. |
| 74 | +java.lang.IllegalStateException: Package 'com.azure.resourcemanager.<pkg>' is not supported by Fluent Premium |
| 75 | +``` |
| 76 | +
|
| 77 | +**Root cause:** `tspconfig.yaml` enables an emitter option (for example `premium: true`) that is not supported for the target package. |
| 78 | +
|
| 79 | +**Solution:** Remove the unsupported option from `options.@azure-tools/typespec-java`. |
| 80 | +
|
| 81 | +--- |
| 82 | +
|
| 83 | +### 1.3 Verify Swagger and TypeSpec Code Generation fails |
| 84 | +**Log signal:** |
| 85 | +- Verify Swagger and TypeSpec Code Generation check fails in Java SDK CI - java-pullrequest |
| 86 | +
|
| 87 | +**Error (real-world example):** |
| 88 | +``` |
| 89 | +Exception: /mnt/vss/_work/1/s/eng/scripts/Compare-CurrentToCodegeneration.ps1:225 |
| 90 | +Line | |
| 91 | + 225 | $job | Receive-Job 2>$null | Out-Null |
| 92 | + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 93 | + | ScriptHalted |
| 94 | + |
| 95 | +##[error]PowerShell exited with code '1'. |
| 96 | +``` |
| 97 | +
|
| 98 | +**Root cause:** |
| 99 | +The **Verify Swagger and TypeSpec Code Generation** step in the Java SDK PR pipeline re-runs code generation using repository-local configuration and compares regenerated output with committed code. This check usually fails because regeneration produces large diffs. |
| 100 | +Common causes include: |
| 101 | +- `tspconfig.yaml` has incorrect Java emitter settings. |
| 102 | +- In `tspconfig.yaml`, `api-version` changes can directly change operation/model counts. |
| 103 | +- In `tspconfig.yaml`, `enable-sync-stack` changes can add or remove a large set of sync client classes. |
| 104 | +- In `tspconfig.yaml`, `flavor` changes (for example, `azure` vs `standard`) change generated code style and shape. |
| 105 | +
|
| 106 | +When operation counts change significantly, **api-version drift** is the most common cause. If `api-version` is not explicitly fixed in `tspconfig.yaml`, it may default to the latest version, which can differ from the version used when the checked-in SDK was originally generated. |
| 107 | +
|
| 108 | +**Solution:** |
| 109 | +1. Check the pipeline code-generation diff, re-run local generation with the same repository configuration, compare against the SDK output in the generated PR, and update the relevant `tspconfig.yaml` settings (for example `api-version`, `enable-sync-stack`, `flavor`). |
| 110 | +2. Update `tspconfig.yaml` in the spec repo PR, commit the change, and rerun generation to regenerate the SDK PR. |
| 111 | +
|
| 112 | +Example (API version mismatch): pin `api-version` in `tspconfig.yaml` so the Verify step and SDK generation use the same version, then rerun generation. |
| 113 | +```yaml |
| 114 | +options: |
| 115 | + "@azure-tools/typespec-java": |
| 116 | + api-version: "2025-12-01" # ✅ pin the api-version used for generation |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 2. Customization Errors |
| 122 | + |
| 123 | +**How to identify:** `[COMPILE] Maven build fail.` with Java compilation errors referencing hand-written classes/methods that no longer exist in generated code. The pipeline may auto-retry with customization disabled and show: |
| 124 | +``` |
| 125 | +Generate a fresh package from TypeSpec. If there was prior customization on the package, |
| 126 | +please check whether it causes failure, and fix them before apiview. |
| 127 | +``` |
| 128 | + |
| 129 | +> **Background:** Azure SDK packages usually contain both *generated code* (auto-produced from TypeSpec) and *customization code* (hand-written by SDK developers): |
| 130 | +> - *generated code*: produced by the generator; API surface may change when the spec or generator changes, which can break compilation. |
| 131 | +> - *customization code*: maintained by SDK developers; commonly wired via `customization-class` and preserved during regeneration with `partial-update: true`. |
| 132 | +> |
| 133 | +> Reference: autorest.java customization-base: https://github.com/Azure/autorest.java/tree/main/customization-base |
| 134 | +
|
| 135 | +**Prerequisites for customization:** When adding customization code, two options must be set in `tspconfig.yaml`: |
| 136 | +```yaml |
| 137 | +options: |
| 138 | + "@azure-tools/typespec-java": |
| 139 | + customization-class: "com.azure.resourcemanager.yourservice.customization" |
| 140 | + partial-update: true |
| 141 | +``` |
| 142 | +- **`customization-class`** — the Java package containing your hand-written customization classes |
| 143 | +- **`partial-update`** — set to `true` so the generator preserves your custom files instead of overwriting the entire output directory |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## 3. Intermittent Errors |
| 148 | + |
| 149 | +**How to identify:** The failure is in dependency download, npm install, or CI infrastructure — not in generation/compilation logic. Error messages mention network timeouts, `Could not resolve dependencies`, `Could not transfer artifact`, or failures in injected DevOps tasks. |
| 150 | + |
| 151 | +**Solution for all intermittent errors: Re-run the pipeline.** |
| 152 | + |
| 153 | +> **If failure persists after 2-3 retries**, it is likely a genuine issue, not intermittent. Review the error details and consult sections 1 or 2 above. |
| 154 | + |
| 155 | +### 3.1 Maven Dependency Download Failure |
| 156 | + |
| 157 | +**Error:** `[COMPILE] Maven build fail.` with `Could not resolve dependencies` / `Could not transfer artifact` / connection timeout. |
| 158 | + |
| 159 | +**Error (real-world example):** |
| 160 | +``` |
| 161 | +[FATAL] Non-resolvable parent POM for com.azure:customization-loader:1.0.0-beta.1: |
| 162 | +Could not transfer artifact ... from/to central (https://repo.maven.apache.org/maven2): |
| 163 | +Connect to repo.maven.apache.org:443 ... failed: Network is unreachable (connect failed) |
| 164 | +and 'parent.relativePath' points at wrong local POM |
| 165 | +``` |
| 166 | +
|
| 167 | +--- |
| 168 | +
|
| 169 | +## Escalation |
| 170 | +
|
| 171 | +If the issue persists after following this guide, post in the [Language - Java Teams channel][teams-java] with: |
| 172 | +- Spec PR link |
| 173 | +- Pipeline build link and build ID |
| 174 | +- Exact error message |
| 175 | +- What you've already tried |
| 176 | +
|
| 177 | +Other resources: [TypeSpec GitHub](https://github.com/microsoft/typespec) | [Troubleshoot PR failures](https://eng.ms/docs/products/azure-developer-experience/support/troubleshoot/PR-failing) | [SDK support](https://eng.ms/docs/products/azure-developer-experience/support/support#get-help-with-the-azure-sdks-development) |
| 178 | +
|
| 179 | +<!-- Reference Links --> |
| 180 | +[teams-java]: https://teams.microsoft.com/l/channel/19%3a5e673e41085f4a7eaaf20823b85b2b53%40thread.skype/Language%2520-%2520Java?groupId=3e17dcb0-4257-4a30-b843-77f47f1d4121&tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47 "Language - Java Teams channel" |
0 commit comments