Skip to content

build: name the KSP predicate the two schema rules share - #1714

Merged
ryanbr merged 1 commit into
mainfrom
gradle-ksp-matcher-extract
Aug 28, 2026
Merged

ryanbr merged 1 commit into
mainfrom
gradle-ksp-matcher-extract

Conversation

@ryanbr

@ryanbr ryanbr commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Follow-up to #1712, which is where the need showed up.

Why

That change added a matcher spelled startsWith("ksp") && endsWith("Kotlin") a few lines below one that already existed and read almost identically — and the existing one deliberately inverts on the UnitTest/AndroidTest rounds. I did not notice while writing it, which is the argument for this change rather than against it: two near-identical predicates meaning opposite things is a trap regardless of who reads them next.

What

fun isKspKotlinTask(name: String) = name.startsWith("ksp") && name.endsWith("Kotlin")

fun isMainSourceSetKspTask(name: String) =
    isKspKotlinTask(name) && !name.contains("UnitTest") && !name.contains("AndroidTest")

syncRoomSchemaSnapshot's mustRunAfter now calls isKspKotlinTask directly, and the comment on the shared half states the opposition instead of leaving it to be diffed by eye:

  • isMainSourceSetKspTask excludes those rounds, so Gradle is not told they output a directory they never write and then clears it out from under the round that did.
  • mustRunAfter includes them, because they still race the Sync.

Pure refactor

Both predicates were checked name by name against every KSP and compile task name this project generates — kspFullDebugKotlin, kspFullReleaseKotlin, the demo variants, the UnitTest and AndroidTest rounds, kspFullDebugJava, compileFullDebugKotlin. Neither predicate changes for any of them.

Verified anyway

The failure mode in this area is a missing schema export, not a compile error, so it does not announce itself:

check result
the three-task command from #1712 BUILD SUCCESSFUL
KSP rounds debug, unit-test, release — once each
unit suite 4,725 tests, 0 failures
SchemaOracleTest 4/4 — the test that fails when the export goes missing

Run before and after the comment relocation described below, with identical results.

One note on the diff

My first version of this inserted the new declaration between the pre-existing comment block and the function it documents, orphaning the "load-bearing" exclusion rationale onto the wrong function. Caught in review and moved above the block. Worth mentioning because it is the exact hazard this PR exists to reduce — and because a comment attached to the wrong function is invisible to every check in CI.

Follow-up to #1712, which is where the need showed up. That change added a matcher spelled
`startsWith("ksp") && endsWith("Kotlin")` a few lines below one that already existed and read almost
identically — and the existing one deliberately INVERTS on the UnitTest/AndroidTest rounds. I did not
notice while writing it, which is the argument for this: two near-identical predicates meaning
opposite things is a trap regardless of who reads them next.

The shared half is now named, and the comment on it states the opposition rather than leaving it to be
diffed by eye: isMainSourceSetKspTask excludes those rounds so Gradle is not told they output a
directory they never write and then clears it from under the round that did, while
syncRoomSchemaSnapshot's mustRunAfter includes them because they still race the Sync.

Pure refactor. Both predicates were checked name by name against every KSP and compile task name this
project generates, and neither changes for any of them.

Verified anyway, because the failure mode here is a missing schema export rather than a compile error:
the three-task command from #1712 still succeeds, the debug, unit-test and release rounds still run
exactly once each, 4,725 tests pass, and SchemaOracleTest — the test that fails when the export goes
missing — is 4 for 4.
@ryanbr
ryanbr merged commit bebfd30 into main Aug 28, 2026
4 checks passed
@ryanbr
ryanbr deleted the gradle-ksp-matcher-extract branch August 28, 2026 12:16
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.

1 participant