Make the gate one command, and add static analysis behind a baseline

Everything this repository promised was voluntary until now: 371 tests, lint and the generated code
map ran only if whoever changed the code remembered to run them. tools/verify.sh is that gate as one
command - the map check, detekt, the unit tests and lint, cheapest first so a stale document fails in
a second rather than after a release build - and --release adds the R8 build. The ordering is not
cosmetic: the two cheapest checks are also the two that catch drift nothing else can see.

The same script runs in three places: CI on every push and pull request, a nightly --release job (R8
is the one check nothing else performs, and it has hidden a real defect here once), and a pre-push
hook once the clone has been told to use .githooks. The nightly also uploads the R8 mapping, which is
what turns a release stack trace back into a line of Kotlin and is only worth keeping if it belongs
to the build that shipped.

Detekt is adopted with a baseline, which is the entire adoption strategy: everything it finds today
is frozen in config/detekt/baseline.xml, so the gate fails on a new finding rather than on a backlog
nobody is going to clear this week. Entries are keyed by rule, file and enclosing declaration, so a
new long function is still reported inside a file that already has one - proved by writing a TODO
into a file, watching the build fail on that exact line, and taking it out again. What it found
first agrees with the churn numbers from the last pass: ArchiveEngine 16 findings, BrowserViewModel
11, SelectionBar 9, 86 in total over 13 rules, the largest groups being the complexity ones this was
added for (cyclomatic complexity 10, nested block depth 7, too many functions 4, long methods 3, two
classes over 700 lines) plus 30 over-long lines.

Three findings were fixed rather than parked, because they were real: dead `menuOpen` state left in
BrowserScreen when the overflow menu moved into BrowserTopBar, a missing trailing newline, and two
`db` parameters that are the platform's signature rather than an oversight (suppressed with that
reason written next to them). Four rules were configured rather than obeyed: PackageNaming, because
the applicationId's underscore is an identity this app cannot change; FunctionNaming, for @Composable
(PascalCase by convention) and for backticked test names, which is the project's specification style;
MagicNumber, because sizes and limits are named constants here; and MatchingDeclarationName, because
a file is named after its concept rather than after a declaration inside it.

Two tooling facts cost real time and are in neither tool's documentation. Detekt runs through its CLI
rather than its Gradle plugin: the plugin performs the analysis inside the build's own JVM, and
detekt 1.23 cannot parse JDK 25's version string - it fails with "25.0.4.1" as the entire error
message - so the task drives detekt-cli on a 21 launcher, which is also the only way to pin the JVM
the analyser runs on. And a baseline has to exist before it can be read, which is why it starts as an
empty document rather than being generated into place.

Verified: the fast gate is green in 17 seconds, --release adds a 36-second R8 build, 371 JVM tests
still pass, lint is clean and the map is current. CHANGELOG, README, AGENTS.md, ROADMAP (the gate is
now a recorded decision) and the regenerated map carry it.
This commit is contained in:
2026-10-17 09:13:32 +02:00
parent 0743bda29e
commit b1bc805af0
16 changed files with 418 additions and 15 deletions
+76
View File
@@ -1,4 +1,6 @@
import java.util.Properties
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.testing.Test
plugins {
@@ -6,6 +8,11 @@ plugins {
alias(libs.plugins.kotlin.compose)
}
/*
* Static analysis for the Kotlin side of the app (Android Lint covers the rest) — see the two tasks
* at the bottom of this file. Nothing to configure here: the CLI is driven by them.
*/
// Optional release signing.
//
// Create a `keystore.properties` file in the project ROOT (it is git-ignored; see
@@ -197,3 +204,72 @@ dependencies {
// Lets a ViewModel test drive `viewModelScope` on a deterministic dispatcher.
testImplementation(libs.kotlinx.coroutines.test)
}
// ---------------------------------------------------------------- static analysis
/** The detekt CLI, on a configuration of its own so it never becomes an app dependency. */
val detektCli: Configuration by configurations.creating {
isCanBeConsumed = false
}
dependencies {
detektCli(libs.detekt.cli)
}
/**
* Command line shared by [detekt] and [detektBaseline].
*
* The CLI rather than the Gradle plugin, for one concrete reason: the plugin runs the analysis
* inside the build's own JVM, and detekt 1.23 cannot make sense of the version string of the JDK 25
* this project builds with — it fails with `25.0.4.1` as the entire error message. Running the CLI
* through [JavaExec] also lets the analyser run on a 21 launcher, which it does understand.
*/
fun detektArguments(vararg extra: String): List<String> = listOf(
"--input", "src/main/java,src/test/java",
"--config", rootProject.file("config/detekt/detekt.yml").absolutePath,
// The sources use Java 17 language features, which is what compileOptions asks for as well.
"--jvm-target", "17",
// config/detekt/detekt.yml only lists overrides; everything else is detekt's default.
"--build-upon-default-config",
"--parallel",
) + extra
val detektJava = javaToolchains.launcherFor {
languageVersion.set(org.gradle.jvm.toolchain.JavaLanguageVersion.of(21))
}
val detektReports = layout.buildDirectory.dir("reports/detekt")
/**
* Kotlin static analysis, failing on any finding not frozen in `config/detekt/baseline.xml`.
*
* The baseline is the whole adoption strategy: everything detekt finds today is parked there, so the
* gate fails on a *new* finding rather than on a backlog nobody is going to clear this week. Entries
* are keyed by rule, file and enclosing declaration, so a new long function is still reported even in
* a file that already has one.
*/
val detekt by tasks.registering(JavaExec::class) {
group = "verification"
description = "Kotlin static analysis against config/detekt, minus the baseline."
classpath = detektCli
mainClass.set("io.gitlab.arturbosch.detekt.cli.Main")
javaLauncher.set(detektJava)
args = detektArguments(
"--baseline", rootProject.file("config/detekt/baseline.xml").absolutePath,
"--report", "html:" + detektReports.get().file("detekt.html").asFile.absolutePath,
"--report", "sarif:" + detektReports.get().file("detekt.sarif").asFile.absolutePath,
)
}
/** Rewrites the baseline with whatever detekt finds right now. Run it deliberately, not to go green. */
val detektBaseline by tasks.registering(JavaExec::class) {
group = "verification"
description = "Rewrites config/detekt/baseline.xml with the findings that exist now."
classpath = detektCli
mainClass.set("io.gitlab.arturbosch.detekt.cli.Main")
javaLauncher.set(detektJava)
args = detektArguments(
"--baseline", rootProject.file("config/detekt/baseline.xml").absolutePath,
"--create-baseline",
)
}