Skip to content

Fix Maven scope and version selection in the POM dependency report#690

Merged
alexander-yevsyukov merged 5 commits into
masterfrom
group-of-fixes
Jun 15, 2026
Merged

Fix Maven scope and version selection in the POM dependency report#690
alexander-yevsyukov merged 5 commits into
masterfrom
group-of-fixes

Conversation

@alexander-yevsyukov

Copy link
Copy Markdown
Contributor

What & why

The aggregated dependency report (docs/dependencies/pom.xml in consumer repos)
could mislabel a production dependency as <scope>test</scope> whenever a
test-only module happened to depend on the same artifact. Observed in
SpineEventEngine/core-jvm-compiler PR #94,
where io.spine:spine-base — an api dependency of production modules — flipped
to test scope.

Root cause: deduplicate() collapsed same-GAV entries with
distinctBy { it.gav }, keeping the first-encountered occurrence, whose
configuration then dictated the reported scope. Version selection was also a
plain lexicographic string compare, so 9.2.0 incorrectly outranked 10.0.0.

Changes

  • Scope mergededuplicate() now groups by group:name, retains the
    newest version, and among that version's usages reports the widest Maven
    scope. A dependency used via api in one module and testImplementation in
    another is reported as compile, not test.
  • VersionComparator (new) — numeric-aware, SemVer-flavored version
    ordering: 10.0.0 > 9.2.0, 2.0.0-SNAPSHOT.100 > 2.0.0-SNAPSHOT.99,
    release > pre-release. Replaces the lexicographic compare. No new dependency.
  • dependencyPriority() — re-ranked into the conventional Maven scope order
    (compile < provided < runtime < test < system < undefined) as an exhaustive
    when over the scope enum. The single ranking drives both scope selection and
    pom.xml layout, so compileOnly/annotationProcessor usages report as
    provided rather than test.

Tests

  • VersionComparatorSpec — 7 tests (numeric ordering, release-vs-pre-release,
    segment edge cases).
  • DependencyWriterSpec — 19 tests (ProjectBuilder-based): scope precedence,
    numeric version selection, and the end-to-end pom.xml regression.

./gradlew :buildSrc:test detekt green; spine-code-review, kotlin-engineer,
and review-docs all APPROVE.

Also on this branch

group-of-fixes bundles two small unrelated commits: an SSH log-message typo
fix (SshKey.kt) and agent-memory additions under .agents/memory/.

One-time downstream effect

On the next regeneration, consumer pom.xml reports list provided
dependencies above runtime — a one-time layout shift toward the Maven
convention.

🤖 Generated with Claude Code

alexander-yevsyukov and others added 5 commits June 15, 2026 15:48
The aggregated dependency report (`docs/dependencies/pom.xml` in consumer
repos) could mark a production dependency as `test` scope when a test-only
module also used the same artifact. `deduplicate()` collapsed same-GAV entries
with `distinctBy { it.gav }`, keeping the first-encountered occurrence, whose
configuration then dictated the reported scope. Observed in
`core-jvm-compiler` PR #94, where `io.spine:spine-base` flipped to `test`.

Rework `deduplicate()` to group by `group:name`, retain the newest version,
and among that version's usages report the widest Maven scope. Version
selection now uses a new numeric-aware `VersionComparator` instead of a
lexicographic string compare, so `10.0.0` outranks `9.2.0` and
`2.0.0-SNAPSHOT.100` outranks `...99`. `dependencyPriority()` is re-ranked into
the conventional Maven order (compile < provided < runtime < test < system <
undefined) and drives both scope selection and `pom.xml` layout, so
`compileOnly`/`annotationProcessor` usages report as `provided` rather than
`test`.

Add `VersionComparatorSpec` (7 tests) and `DependencyWriterSpec` (19 tests,
ProjectBuilder-based) covering scope precedence, numeric version selection, and
the end-to-end `pom.xml` regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alexander-yevsyukov alexander-yevsyukov merged commit da21824 into master Jun 15, 2026
3 checks passed
@alexander-yevsyukov alexander-yevsyukov deleted the group-of-fixes branch June 15, 2026 15:30
@github-project-automation github-project-automation Bot moved this from 🏗 In progress to ✅ Done in v2.0 Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes correctness issues in the Gradle-to-POM dependency report generator used across Spine SDK consumer repos, ensuring duplicated dependencies are reported with the newest semantic version and the widest (most production-relevant) Maven scope.

Changes:

  • Reworked dependency de-duplication to (a) select the newest version via a numeric-aware comparator and (b) select the widest Maven scope among usages of that retained version.
  • Introduced VersionComparator (SemVer-flavored ordering) and added end-to-end and unit tests covering scope precedence and version selection.
  • Minor maintenance updates: scope-priority ordering aligned with Maven conventions; SSH log message typo fixed; added/updated agent task + memory docs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/DependencyWriter.kt Fixes de-duplication to choose newest semantic version and widest scope for the retained version.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/ScopedDependency.kt Updates scope priority to conventional Maven order (compile → provided → runtime → test → system → undefined).
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/VersionComparator.kt Adds a numeric-aware version comparator to avoid lexicographic mis-ordering (e.g., 10.x vs 9.x).
buildSrc/src/test/kotlin/io/spine/gradle/report/pom/DependencyWriterSpec.kt Adds regression and precedence tests for scope merging, version selection, and XML layout ordering.
buildSrc/src/test/kotlin/io/spine/gradle/report/pom/VersionComparatorSpec.kt Adds focused unit tests for semantic version comparison edge cases.
buildSrc/src/main/kotlin/io/spine/gradle/github/pages/SshKey.kt Fixes an SSH config log message typo (“key file” → “config file”).
.agents/tasks/archive/pom-report-scope-merge.md Archives the task plan/log for the dependency report scope/version fixes.
.agents/memory/project/porting-buildsrc-from-consumer-repos.md Adds guidance for back-porting buildSrc improvements from consumer repos.
.agents/memory/project/config-build-verification.md Documents the correct local verification command for buildSrc changes in config.
.agents/memory/MEMORY.md Registers the newly added project memory entries in the index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants