Verify version increment before publishing to Maven Local - #708
Conversation
Projects that publish artifacts to Maven Local for their integration tests (e.g. core-jvm-compiler) must bump the project version before `./gradlew build`; otherwise a local publish overwrites an already-published version and the integration tests pick up a stale artifact. Previously `checkVersionIncrement` was disabled outside CI pull requests, so a missing bump was only caught at PR time. Now every `publishToMavenLocal` task depends on `checkVersionIncrement`, and the static `enabled = false` gate is replaced with an `onlyIf` that also runs the check for local (non-CI) Maven Local publishes. The local path is gated by `!Build.ci` so that CI pushes and tag builds that publish locally (e.g. to feed integration tests) keep succeeding even though their version is already published, preserving the original behavior that avoids failing master re-builds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea8010142f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR updates the IncrementGuard Gradle plugin (in buildSrc) so checkVersionIncrement is evaluated before publishing to Maven Local, not only during CI pull requests, preventing local publishes from silently overwriting already-published versions that integration tests might later consume.
Changes:
- Adds a
mustVerify(ciPullRequest, onCi, localPublish)predicate and switches fromenabled=falseto anonlyIfspec so the check can run for local Maven Local publishes. - Wires
checkVersionIncrementas a dependency of both thechecklifecycle task and allPublishToMavenLocaltasks. - Expands tests to cover
mustVerifydecisions and to assert the Gradle task dependency wiring.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| buildSrc/src/main/kotlin/io/spine/gradle/publish/IncrementGuard.kt | Adds the new verification predicate, switches gating to onlyIf, and wires the check before check and publishToMavenLocal. |
| buildSrc/src/test/kotlin/io/spine/gradle/publish/IncrementGuardTest.kt | Adds decision-table tests for mustVerify and wiring tests for check and PublishToMavenLocal dependencies. |
Follow-up to #708, whose auto-merge landed before this fix; addresses the Codex P2 review comment left on that PR. The `onlyIf` predicate scanned the entire multi-project task graph, so in a build like `:lib:check :app:publishToMavenLocal` the `:lib` check ran against the already-published version of `:lib` even though only `:app` was being published, causing an unexpected network call or a spurious failure of the unrelated `check`. Filter the graph to publishing tasks owned by the same project as the check task, matching the per-project `dependsOn` wiring. The scan is extracted into the testable `IncrementGuard.localPublishPlanned(tasks, project)` companion function, with two new `ProjectBuilder` tests covering the own-project and sibling-project cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
What
IncrementGuardnow runs thecheckVersionIncrementtask before publishing to Maven Local, not only on CI pull requests.publishToMavenLocaltask now depends oncheckVersionIncrement(viatasks.withType(PublishToMavenLocal::class.java).configureEach { dependsOn(...) }).enabled = falsegate is replaced with anonlyIfpredicate, so the check actually runs for local (non-CI) Maven Local publishes.checkis wired lazily through the existingio.spine.gradle.base.checkaccessor instead of eagergetByName.Why
Projects like
core-jvm-compilerpublish artifacts to~/.m2so their integration tests consume them. Bumping the project version before./gradlew buildis critical there: without a bump, a local publish overwrites an already-published version and the integration tests silently pick up a stale artifact. The previous guard only fired on CI pull requests, catching the problem too late.CI safety
The local-publish path is gated by
!Build.ci. CI pushes and tag builds that publish locally (e.g. to feed integration tests) keep succeeding even when their version is already published — preserving the original behavior that avoids failingmasterre-builds. The decision is a pure functionmustVerify(ciPullRequest, onCi, localPublish):masterre-builds stay greenTrade-off
A local
publishToMavenLocalnow fetchesmaven-metadata.xmlfrom the registry first — this is the intended safeguard. Offline local publishes need network access or the documented escape hatch-x checkVersionIncrement.Testing
./gradlew :buildSrc:build detekt(JDK 17) passes — compilation,validatePlugins, all tests, and detekt. Added 6IncrementGuardTestcases: a 4-row truth table formustVerifyand 2ProjectBuilderwiring tests asserting bothcheckand aPublishToMavenLocaltask depend oncheckVersionIncrement.🤖 Generated with Claude Code