[#11767] Fix consumer POM builder failing to resolve BOM imports from…#11768
[#11767] Fix consumer POM builder failing to resolve BOM imports from…#11768DavidTavoularis wants to merge 2 commits intoapache:masterfrom
Conversation
…s from settings.xml profile repositories DefaultConsumerPomBuilder.buildModel() now passes repositories, profiles, and active profile IDs to the ModelBuilderRequest so that BOM imports from non-central repositories (e.g. defined in settings.xml profiles) can be resolved during consumer POM transformation. DefaultModelBuilder.derive() now respects the request's repositories instead of always reusing the parent session's, and caches the RepositoryFactory lookup. Includes unit tests for both fixes and an integration test (apachegh-11767). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet
left a comment
There was a problem hiding this comment.
Review
The fix correctly addresses the root cause: DefaultConsumerPomBuilder.buildModel() wasn't passing repositories/profiles to the ModelBuilderRequest, and DefaultModelBuilder.derive() was ignoring request repositories. The integration test is solid. A few observations:
1. The derive() change is broad. The repository override is applied in the general derive(ModelBuilderRequest, DefaultModelBuilderResult) method, which affects all derived sessions — not just BUILD_CONSUMER. This could have unintended side effects on other request types. Consider scoping the override to only apply for BUILD_CONSUMER requests.
2. Lazy RepositoryFactory caching. The new getRepositoryFactory() with lazy init adds a mutable field. This could be simplified by calling session.getService(RepositoryFactory.class) directly (likely already cached in the session), avoiding the extra state.
3. The instanceof InternalMavenSession check is fragile. Profile/activeProfileIds injection only works when the session is an InternalMavenSession. In embedded or testing contexts, profiles silently won't be passed. Worth documenting or handling explicitly.
4. Unit test uses reflection. testDeriveSessionUsesRequestRepositories accesses mainSession, repositories, and externalRepositories via reflection, making it brittle to field renames. Consider adding package-private accessors or testing behavior indirectly (e.g., verify BOM resolution succeeds from a custom repo).
5. Integration test is well done. MavenITConsumerPomBomFromSettingsRepoTest with the local repo + settings.xml profile setup is the most valuable part — good coverage of the real-world scenario.
Claude Code on behalf of Guillaume Nodet
…MER, remove reflection - Scope repository override in derive() to BUILD_CONSUMER requests only, preventing unintended side effects on parent POM resolution - Remove repositoryFactory caching field, inline session.getService() calls - Add LOGGER.debug for non-InternalMavenSession to document the limitation - Replace reflection-based test with package-private accessors on ModelBuilderSessionState (getRepositories/getExternalRepositories) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
All 4 review items addressed. Here's a summary of the changes:
|
… settings.xml profile repositories
DefaultConsumerPomBuilder.buildModel() now passes repositories, profiles, and active profile IDs to the ModelBuilderRequest so that BOM imports from non-central repositories (e.g. defined in settings.xml profiles) can be resolved during consumer POM transformation.
DefaultModelBuilder.derive() now respects the request's repositories instead of always reusing the parent session's, and caches the RepositoryFactory lookup.
Includes unit tests for both fixes and an integration test (gh-11767).
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.