Repository navigation
Fix #13985: Do not reuse imported dependency management cached without locations - #13988
Conversation
…without locations The dependency management of an imported BOM was cached under its groupId:artifactId:version and the "import" tag, whatever the location tracking of the build that imported it. When the BOM was first imported by a model built without location tracking, e.g. while reading the POM of a build extension, a later project build with location tracking reused that copy, and the managed dependencies it contributed had no InputLocation. Cache the dependency management of builds with location tracking under a separate tag, so they never pick up a copy without locations.
gnodet-bot
left a comment
There was a problem hiding this comment.
Clean, minimal fix for a real cache contamination bug. The new IMPORT_WITH_LOCATIONS tag correctly mirrors the existing IMPORT tag, and the tag selection logic is sound. The test properly validates the failure mode.
Metadata suggestions:
- 🏷️ Suggested milestone: 3.10.2
- 🔙 Backport: not needed (the issue can't occur on
masterwhere the XML parser always records locations)
💡 FYI (no action needed): The same cache contamination pattern exists in the
readParent/RAWpath — if a parent POM is ever cached without location tracking and later requested with it, the same stale-entry problem would occur. Out of scope for this PR, but worth a follow-up issue.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes separating BOM import cache entries by location-tracking mode.
No open issues 🎉
What changed in this PR
Fixes #13985 by separating imported BOM dependency-management cache entries by location-tracking mode, preventing project builds from reusing entries that lack source locations.
Changes:
- Adds an
import-with-locationscache tag while preservingimportfor builds without location tracking. - Uses the selected tag consistently for cache reads and writes.
- Adds a regression test that shares a cache between untracked and tracked builds and checks the managed version’s location.
| File | Description |
|---|---|
maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java |
Adds the shared-cache regression test and an in-memory cache helper. |
maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java |
Defines the location-aware import cache tag. |
maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java |
Selects the import cache tag according to location tracking. |
Review effort: Balanced
|
Hello, Thanks for the fix! Could you please explain to me your release process? When do I expect to have the fix when I download maven binary from official website? I v just seen that it was on 3.10.x, will it be backported to 3.9.6? |
…ement cached without locations (#14117) Backport of #13988 to `maven-4.0.x`. The dependency management of an imported BOM was cached under its groupId:artifactId:version and the "import" tag, whatever the location tracking of the build that imported it. When the BOM was first imported by a model built without location tracking (e.g. while reading the POM of a build extension), a later project build with location tracking reused that copy, and the managed dependencies it contributed had no InputLocation. Cache the dependency management of builds with location tracking under a separate tag, so they never pick up a copy without locations. Cherry-picked from 171a3f4 (adapted: test moved from maven-model-builder/ to compat/maven-model-builder/). Co-authored-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
…t locations (#14118) Port of #13988 (maven-3.10.x) to master. The dependency management of an imported BOM was cached under its groupId:artifactId:version and the "import" tag, whatever the location tracking of the build that imported it. When the BOM was first imported by a model built without location tracking (e.g. while reading the POM of a build extension), a later project build with location tracking reused that copy, and the managed dependencies it contributed had no InputLocation. Cache the dependency management of builds with location tracking under a separate tag, so they never pick up a copy without locations. --------- Co-authored-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
The dependency management of an imported BOM is cached under groupId:artifactId:version and the
importtag, whatever the location tracking of the build that imported it. The model cache lives for the whole session, so when the BOM is first imported by a model built without location tracking (e.g. the POM of a build extension, read through the artifact descriptor reader), a later project build with location tracking reuses that copy and the managed dependencies it contributes have noInputLocation.This caches the dependency management of builds with location tracking under a separate tag,
import-with-locations, so they never pick up a copy without locations. Builds without location tracking keep using the existingimporttag.Added a test in
DefaultModelBuilderTestthat builds a POM importing a BOM twice with the sameModelCache, first without and then with location tracking, and checks that the managed dependency version has a location. It fails without the change.The raw parent cache (
ModelCacheTag.RAWinreadParent) is keyed the same way, so a parent resolved from a repository and first read without location tracking can still end up without locations. I left it out to keep this change focused on the reported case; happy to follow up if wanted.The same code is on maven-3.9.x, so this could be backported there if you think it is worth it.
masterdoesn't seem affected, since the XML parser there always records locations.Fixes #13985
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following: