[#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 into
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:
|
gnodet
left a comment
There was a problem hiding this comment.
Re-review after feedback commit (4d5cd97)
The second commit cleanly addresses all 5 observations from the previous review:
-
derive() scoped to BUILD_CONSUMER -- The repository override in
derive()is now guarded byrequest.getRequestType() == ModelBuilderRequest.RequestType.BUILD_CONSUMER, so parent POM resolution and other derived sessions are not affected. Good. -
RepositoryFactory caching removed -- The mutable
repositoryFactoryfield andgetRepositoryFactory()method are gone. The service is looked up inline viasession.getService(RepositoryFactory.class)at both call sites. Simpler and correct. -
Non-InternalMavenSession handling -- The
elsebranch now logs aLOGGER.debug()message explaining that settings.xml profiles won't be passed in embedded/testing contexts. This makes the limitation visible rather than silent. -
Reflection removed from unit test --
testBuildConsumerWithExplicitRepositoriesuses package-private accessors (getRepositories()/getExternalRepositories()) onModelBuilderSessionStateinstead of reflection. The test is in the same package (org.apache.maven.impl.model), so this works cleanly and is resilient to refactoring. -
Integration test unchanged -- Still the most valuable part of the PR, verifying end-to-end BOM resolution from a settings.xml profile repository with consumer POM flattening.
The ConsumerPomBuilderTest addition using Mockito spy to capture and verify the ModelBuilderRequest is also well structured -- it confirms the request carries repositories without depending on internal state.
One minor note: no CI checks have run on this branch yet. Worth confirming CI passes before merge.
LGTM.
Claude Code on behalf of Guillaume Nodet
… 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). Contributed by DavidTavoularis Closes #11768 Fixes #11767
… 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.