Skip to content

feat(matrix): Fetch AGP<->Kotlin compat dynamically#1166

Merged
romtsn merged 8 commits intomainfrom
rz/feat/dynamic-agp-kotlin-compat
Apr 24, 2026
Merged

feat(matrix): Fetch AGP<->Kotlin compat dynamically#1166
romtsn merged 8 commits intomainfrom
rz/feat/dynamic-agp-kotlin-compat

Conversation

@romtsn
Copy link
Copy Markdown
Member

@romtsn romtsn commented Apr 23, 2026

#skip-changelog

Replace the static gradleToKotlin dict in scripts/generate-compat-matrix.main.kts with a fetch of the AGP ↔ Kotlin compatibility table from developer.android.com/build/kotlin-support. For each AGP version in the CI matrix we now pick the highest Kotlin whose required AGP is ≤ ours, which is a more direct semantic fit than the previous Gradle→Kotlin hand-picked map and also catches new Kotlin minors automatically.

Follow-up to #1165, which switched the AGP↔Gradle source.

The existing Kotlin→min-Gradle floor check (sourced from kotlinlang.org via fetchKotlinGradleCompatibility) stays in place, so if the chosen Kotlin needs a newer Gradle than AGP does, we still bump Gradle up.

Verified output locally against the four AGP versions the matrix generator picks today:

AGP Kotlin (before) Kotlin (after)
9.3.0-alpha01 2.3.0 2.3.21
9.2.0-rc01 2.1.0 2.3.21
9.2.0 2.1.0 2.3.21
8.13.2 1.8.20 2.3.21

Gradle versions are unchanged.

Replace the static gradleToKotlin dict with a fetch of the AGP/Kotlin
compatibility table from developer.android.com/build/kotlin-support.
For each AGP version we now pick the highest Kotlin whose required AGP
is <= ours, which is a more direct semantic fit and also catches new
Kotlin minors automatically. The existing Kotlin->min-Gradle floor
check (sourced from kotlinlang.org) stays in place.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 961ec25

Comment thread scripts/generate-compat-matrix.main.kts Outdated
Comment thread scripts/generate-compat-matrix.main.kts Outdated
romtsn and others added 2 commits April 23, 2026 13:41
The developer.android.com/build/kotlin-support table lists upcoming
Kotlin minors before they ship (e.g. Kotlin 2.4 with AGP 9.1.0 while
only 2.4.0-Beta* is on Maven Central). Resolve each Kotlin minor to
its latest stable patch by reading kotlin-stdlib's maven-metadata.xml
and drop rows whose minor has no stable release yet, so the generated
matrix never references an unpublished version.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
KSP 2.1.0-1.0.29 is pinned to Kotlin compiler 2.1.0 and fails with
"ksp-2.1.0-1.0.29 is too old for kotlin-2.3.21" when the test matrix
runs the android-instrumentation-sample against newer Kotlin versions.
Bump to 2.3.7, which is the latest KSP2 release — KSP2 is decoupled
from the Kotlin compiler version and works across the Kotlin versions
the matrix now picks from developer.android.com/build/kotlin-support.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread scripts/generate-compat-matrix.main.kts
Comment thread gradle/libs.versions.toml Outdated
romtsn and others added 2 commits April 23, 2026 14:05
The pinned KSP (2.1.0-1.0.29, KSP1) is bound to the Kotlin 2.1 compiler
and fails with "ksp is too old for kotlin-X" when the test matrix picks
newer Kotlin versions from developer.android.com/build/kotlin-support.
Bumping KSP directly breaks the default build because KSP2 requires
Kotlin language version 2.0+, but the default Kotlin in Dependencies.kt
is 1.8.20.

Intercept plugin resolution in settings.gradle.kts: when VERSION_KOTLIN
is set (i.e. the matrix is driving the build), use KSP2 2.3.7, which is
decoupled from the Kotlin compiler. Otherwise leave the pinned KSP1 in
place so default / pre-merge builds keep working.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The settings.gradle.kts resolutionStrategy override didn't work because
plugin-alias requests through the version catalog bypass it — Gradle
rejected the rewrite with "the plugin is already on the classpath with
a different version". Switch to the same pattern the other Kotlin
plugins use: a `BuildPluginsVersion.KSP` field sourced from VERSION_KOTLIN
(KSP2 2.3.7 when Kotlin 2.x, KSP1 2.1.0-1.0.29 otherwise), applied via
`version BuildPluginsVersion.KSP` on both the root `apply false` and the
sample's plugins block.

Verified locally that both default builds (Kotlin 1.8.20, KSP1) and the
matrix path (VERSION_KOTLIN=2.3.21, KSP2) resolve and run
`kspStagingReleaseKotlin` successfully.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread scripts/generate-compat-matrix.main.kts Outdated
Comment thread build.gradle.kts
romtsn and others added 2 commits April 23, 2026 22:08
Two related bugs in the AGP -> Kotlin lookup:

1. `agpVersion >= minAgp` evaluates to false for pre-release AGP with
   the same major.minor.patch as a stable minAgp (semver rule:
   9.3.0-alpha01 < 9.3.0). Strip the pre-release identifier before
   the comparison so a row that should match isn't skipped.

2. `maxByOrNull { it.first }` picks the highest minAgp, not the
   highest Kotlin. Works by coincidence today under monotonic data
   but breaks on ties (e.g. Kotlin 1.4 and 1.5 both require AGP 7.0).
   Switch to `it.second` to select by Kotlin version directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code cleanup from review:
- Add fetchGooglesourceText() and parseVersionOrNull() helpers to
  collapse the repeated URL-base64-decode and try/catch-parse patterns
  across six call sites in the compat fetchers.
- Parse the Kotlin major as an Int in BuildPluginsVersion.KSP instead
  of matching `startsWith("2.")`, so a future Kotlin "20.x" won't be
  misclassified as Kotlin 2.x.

No behavior change; matrix output verified identical.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8bf5535. Configure here.

Comment thread buildSrc/src/main/java/Dependencies.kt
Copy link
Copy Markdown
Contributor

@runningcode runningcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread buildSrc/src/main/java/Dependencies.kt
@romtsn romtsn merged commit 8fa3d2d into main Apr 24, 2026
20 checks passed
@romtsn romtsn deleted the rz/feat/dynamic-agp-kotlin-compat branch April 24, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants