mirror of
https://github.com/google/adk-docs.git
synced 2026-09-14 16:16:59 +08:00
4505cb7e13
## Summary
The published Kotlin API reference has rendered **0.5.0** since it was
last
generated — four releases behind `main`, which is on 0.9.0. This
regenerates it
and fixes the generator that made it impossible.
It is not a forgotten manual step. `tools/kotlin-api-docs/generate.sh`
cannot
run against any adk-kotlin newer than **v0.6.0**.
## Why it was stuck
adk-kotlin moved from Dokka **1.9.20** to **2.2.0** at **v0.7.0**, and
Dokka 2
changed three things the script depends on:
1. **The task is gone.** `dokkaHtmlMultiModule` survives only as a
disabled
stub. Against a v0.9.0 clone, `./gradlew tasks --all` lists it verbatim
as:
```
dokkaHtmlMultiModule - [⚠ V1 tasks disabled] Runs all subprojects …
```
The build fails before generating anything.
2. **The output path moved** from `build/dokka/htmlMultiModule` to
`build/dokka/html`.
3. **Root aggregation is gone.** Dokka 1 inferred the unified
multi-module site
from the subprojects; Dokka 2 requires an explicit
`dependencies { dokka(project(...)) }` block, and adk-kotlin's root
build has
none. So even with the task name fixed there is no combined site to copy
—
only a dozen disconnected per-module ones.
## What this changes
**`tools/kotlin-api-docs/generate.sh`** — the three fixes above, plus a
post-generation check that `index.html` actually renders the requested
version.
Nothing verified that before, which is exactly how a 0.5.0 site sat in
the repo
looking freshly built.
The aggregation block is injected into the throwaway clone the script
already
makes, rather than sent upstream to adk-kotlin. That keeps the whole fix
inside
adk-docs — no second repo, no second review — and makes the module list
a docs
decision rather than an SDK one.
**`docs/api-reference/kotlin/`** — regenerated at 0.9.0. 2,462 files.
## Module coverage changes, and not purely additively
Please review this part specifically; it is the only judgement call
here.
| Module | Before | After | |
|---|---|---|---|
| `core`, `a2a`, `litertlm`, `processor`, `webserver` | ✅ | ✅ |
unchanged |
| `integrations` | ❌ | ✅ | **added** |
| `testing` | ❌ | ✅ | **added** |
| `examples` | ✅ | ❌ | **dropped** |
| `firebase`, `mlkit` | ❌ | ❌ | attempted, produce nothing |
- **`integrations` matters most.** It hosts
`BigQueryAgentAnalyticsPlugin`,
which `docs/integrations/bigquery-agent-analytics.md` documents and the
API
reference has never covered.
- **`examples` is dropped** because it is sample code rather than API
surface,
and it declares a JDK 21 toolchain that fails to auto-provision and
takes the
entire build down with it. Happy to restore it if you disagree, but it
needs
the toolchain problem solved first.
- **`firebase` and `mlkit` aggregate but emit empty directories** —
Dokka 2
generates no pages for their androidMain source sets. I left them out
rather
than shipping empty modules that imply coverage that is not there.
Making them
work needs a Dokka source-set fix in adk-kotlin, so it is out of scope
here.
## Verification
- A clean run of the committed script reproduces this exact tree.
- `index.html` renders `0.9.0`, and no file under
`docs/api-reference/kotlin/`
still contains `0.5.0`.
- The one deep link into the reference —
`docs/runtime/runconfig.md:364`, into
`google-adk-kotlin-core/com.google.adk.kt.agents/-run-config/` — still
resolves.
- The GA tag is injected exactly once per page. Eight files are skipped:
the
`navigation.html` fragments, which have no `<head>` to inject into.
- No temp-clone paths leaked into the generated HTML.
Built with **JDK 26** and Android SDK **platform 34**. adk-kotlin
declares a JDK
17 toolchain, but Dokka never needed to launch it for the aggregated
modules.
## Reviewing 2,462 files
Almost all of it is generated HTML. The only hand-written change is
`tools/kotlin-api-docs/generate.sh` (+57/-13); everything else is Dokka
output.
Reviewing the script and spot-checking a couple of rendered pages is the
useful
version of this review.
## Relationship to #2152
#2152 pins adk-docs to adk-kotlin 1.0.0 and lists regenerating this
reference on
its pre-merge checklist, blocked on a `v1.0.0` tag that does not exist
yet.
This PR deliberately does **not** wait for that. Doing it at 0.9.0 now
clears
four releases of staleness immediately and proves the toolchain works
while
there is no deadline, instead of discovering the generator is broken on
release
day. Once 1.0.0 ships, #2152 re-runs the same script with a different
argument.
162 lines
6.1 KiB
Bash
Executable File
162 lines
6.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Generates Kotlin API reference documentation for adk-kotlin using Dokka.
|
|
# Outputs HTML to docs/api-reference/kotlin/.
|
|
#
|
|
# This script runs in an isolated temporary directory and does not
|
|
# modify any existing adk-kotlin clones or local environments.
|
|
#
|
|
# Prerequisites: java (JDK 17+), Android SDK (ANDROID_HOME must be set), git
|
|
# Run from: adk-docs repository root
|
|
#
|
|
# Usage: bash tools/kotlin-api-docs/generate.sh <version>
|
|
# Example: bash tools/kotlin-api-docs/generate.sh 0.1.0
|
|
#
|
|
# Dokka 2 note: adk-kotlin moved from Dokka 1.9.20 to 2.2.0 at v0.7.0. Dokka 2
|
|
# renamed the generation task and dropped the implicit root aggregation that
|
|
# used to produce the unified multi-module site, so this script pins neither.
|
|
# See AGGREGATED_MODULES below.
|
|
|
|
set -e
|
|
|
|
# Validate arguments
|
|
VERSION="${1:-}"
|
|
if [[ -z "$VERSION" ]]; then
|
|
echo "Usage: $0 <version>"
|
|
echo "Example: $0 0.1.0"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
echo "Error: Version must be in X.Y.Z format (e.g., 0.1.0)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check prerequisites
|
|
if ! command -v java &> /dev/null; then
|
|
echo "Error: java is required but not installed."
|
|
echo " Install with: brew install openjdk@17"
|
|
echo " Then run: sudo ln -sfn \$(brew --prefix openjdk@17)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v git &> /dev/null; then
|
|
echo "Error: git is required but not installed."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$ANDROID_HOME" ]]; then
|
|
echo "Error: ANDROID_HOME is not set."
|
|
echo " Install with: brew install --cask android-commandlinetools"
|
|
echo " Then run:"
|
|
echo " export ANDROID_HOME=\"\$(brew --prefix)/share/android-commandlinetools\""
|
|
echo " yes | sdkmanager --licenses"
|
|
echo " sdkmanager \"platforms;android-34\""
|
|
echo " Add to ~/.zshrc: export ANDROID_HOME=\"\$(brew --prefix)/share/android-commandlinetools\""
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d "$ANDROID_HOME" ]]; then
|
|
echo "Error: ANDROID_HOME is set to '$ANDROID_HOME' but that directory does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
# Validate working directory
|
|
TARGET_DIR="docs/api-reference/kotlin"
|
|
if [[ ! -d "$TARGET_DIR" ]]; then
|
|
echo "Error: Run this script from the adk-docs repository root."
|
|
exit 1
|
|
fi
|
|
|
|
# Create temp workspace
|
|
WORK_DIR=$(mktemp -d)
|
|
trap 'rm -rf "$WORK_DIR"' EXIT
|
|
echo "Using temp workspace: $WORK_DIR"
|
|
|
|
# Build docs in temp workspace
|
|
pushd "$WORK_DIR" > /dev/null || exit 1
|
|
|
|
# Clone adk-kotlin
|
|
echo "Cloning adk-kotlin v${VERSION}..."
|
|
git clone --depth 1 --branch "v${VERSION}" https://github.com/google/adk-kotlin adk-kotlin
|
|
cd adk-kotlin
|
|
|
|
# Dokka 2 builds the unified site from an explicit aggregation list on the root
|
|
# project; Dokka 1's `dokkaHtmlMultiModule` used to infer it from the subprojects.
|
|
# Injecting it into the throwaway clone keeps the whole fix inside adk-docs and
|
|
# needs no change to adk-kotlin.
|
|
#
|
|
# Deliberately excluded:
|
|
# -examples, -examples-android, -examples-java sample apps, not API surface.
|
|
# -examples also declares a JDK 21
|
|
# toolchain, which fails to
|
|
# auto-provision and stops the build.
|
|
# -firebase, -mlkit Android-only library modules. Both
|
|
# are aggregatable and both emit an
|
|
# empty directory -- Dokka 2 produces
|
|
# no pages for their androidMain
|
|
# source sets here. Listing them
|
|
# would imply coverage that does not
|
|
# exist; documenting them needs an
|
|
# adk-kotlin-side Dokka source-set fix.
|
|
echo "Injecting Dokka aggregation for the published modules..."
|
|
cat >> build.gradle.kts <<'AGGREGATED_MODULES'
|
|
|
|
// --- injected by adk-docs tools/kotlin-api-docs/generate.sh ---
|
|
dependencies {
|
|
dokka(project(":google-adk-kotlin-core"))
|
|
dokka(project(":google-adk-kotlin-a2a"))
|
|
dokka(project(":google-adk-kotlin-integrations"))
|
|
dokka(project(":google-adk-kotlin-litertlm"))
|
|
dokka(project(":google-adk-kotlin-processor"))
|
|
dokka(project(":google-adk-kotlin-webserver"))
|
|
dokka(project(":google-adk-kotlin-testing"))
|
|
}
|
|
AGGREGATED_MODULES
|
|
|
|
# Build Dokka HTML docs. The leading colon scopes this to the root project's
|
|
# aggregated publication -- without it Gradle runs the task in every subproject,
|
|
# including the excluded sample apps.
|
|
echo "Building Kotlin API docs with Dokka..."
|
|
./gradlew clean :dokkaGeneratePublicationHtml
|
|
|
|
popd > /dev/null || exit 1
|
|
|
|
# Copy to output directory
|
|
echo "Copying to $TARGET_DIR..."
|
|
rm -rf "$TARGET_DIR"/*
|
|
cp -r "$WORK_DIR/adk-kotlin/build/dokka/html"/* "$TARGET_DIR/"
|
|
|
|
# Add Google Analytics tag to generated HTML files
|
|
echo "Adding Google Analytics tag..."
|
|
GA_TAG_FILE=$(mktemp)
|
|
cat > "$GA_TAG_FILE" <<'EOF'
|
|
<!-- Google Analytics tag (gtag.js) -->
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DKHZS27PHP"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
gtag('config', 'G-DKHZS27PHP');
|
|
</script>
|
|
EOF
|
|
GA_TAG=$(<"$GA_TAG_FILE")
|
|
rm -f "$GA_TAG_FILE"
|
|
export GA_TAG
|
|
find "$TARGET_DIR" -name '*.html' -print0 | while IFS= read -r -d '' file; do
|
|
awk 'BEGIN{tag=ENVIRON["GA_TAG"]} {gsub(/<\/head>/, "\n" tag "\n</head>")}1' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
|
done
|
|
|
|
# The reference sat at 0.5.0 for four releases because nothing ever checked that
|
|
# the committed output matched the version it was generated for. Fail loudly
|
|
# rather than leave a stale site that looks freshly built.
|
|
echo "Verifying rendered version..."
|
|
RENDERED=$(grep -A1 'class="library-version"' "$TARGET_DIR/index.html" | tr -d ' \t\r\n' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
|
if [[ "$RENDERED" != "$VERSION" ]]; then
|
|
echo "Error: index.html renders '${RENDERED:-nothing}' but '$VERSION' was requested."
|
|
exit 1
|
|
fi
|
|
echo "index.html renders $RENDERED."
|
|
|
|
echo "Done."
|