Skip to content

Fix #13100: honor repositories from legitimately-active external model profiles - #13155

Merged
gnodet merged 2 commits into
apache:maven-4.0.xfrom
gnodet:backport/13100-to-4.0.x
Sep 16, 2026
Merged

gnodet merged 2 commits into
apache:maven-4.0.xfrom
gnodet:backport/13100-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Backport of #13141 (master) and #13116 (maven-3.10.x) to maven-4.0.x.

Problem

The withoutRepositories() stripping (compat stack) and the .map() stripping (impl stack) were applied to all active profiles in the externalOrigin branch unconditionally — regardless of why they activated.

The hasFileOrPropertyOrConditionActivation filter already suppresses file- and property-activated profiles before they reach injection. The blanket strip was therefore over-broad: it discarded repositories from legitimately-active profiles (JDK/OS, activeByDefault) with no security benefit, breaking the established pattern:

project → dep1 → dep2

where dep1 declares dep2's non-Central repository inside a JDK- or activeByDefault-activated profile.

Changes

  • compat (maven-model-builder): remove withoutRepositories() call from the profile injection loop; remove the now-dead withoutRepositories() helper method; add TODO(#13146)
  • impl (maven-impl): remove .map() repository stripping from the externalOrigin branch; update comment; add TODO(#13146)
  • tests: flip noneMatch → anyMatch for all externalOrigin=true assertions; add testActiveByDefaultProfileRepositoryHonored() with isolated fixture; rename testDependencyPomActivatesOnlyEnvironmentIndependentProfiles

BUILD_CONSUMER stripping is intentional and unchanged — consumer POMs must not leak profile repositories into the published artifact.

Notes

…l model profiles

Backport of apache#13141 (master) and apache#13116 (maven-3.10.x) to maven-4.0.x.

The withoutRepositories() stripping (compat stack) and the .map() stripping
(impl stack) were applied to all active profiles in the externalOrigin branch
unconditionally — regardless of why they activated.

The hasFileOrPropertyOrConditionActivation filter already suppresses file- and
property-activated profiles before they reach injection. The blanket strip was
therefore over-broad: it discarded repositories from legitimately-active profiles
(JDK/OS, activeByDefault) with no security benefit, breaking the established
pattern where a dependency POM declares a non-Central repository inside a JDK-
or activeByDefault-activated profile.

Changes:
- compat: remove withoutRepositories() call from the profile injection loop;
  remove the now-dead withoutRepositories() helper method; add TODO(apache#13146)
- impl: remove .map() repository stripping from the externalOrigin branch;
  update comment; add TODO(apache#13146)
- tests: flip noneMatch → anyMatch for all externalOrigin=true assertions;
  add testActiveByDefaultProfileRepositoryHonored() with isolated fixture;
  rename testDependencyPomActivatesOnlyEnvironmentIndependentProfiles

BUILD_CONSUMER stripping is intentional and unchanged.
@gnodet gnodet added the bug Something isn't working label Sep 16, 2026
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Sep 16, 2026

@gnodet-bot gnodet-bot 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.

The fix is logically correct: hasFileOrPropertyOrConditionActivation already gates out file/property/condition profiles before getActiveProfiles, so only JDK, OS, and activeByDefault profiles reach the injection loop — removing the blanket repo-strip from those is the right call. The BUILD_CONSUMER branch correctly continues to strip, the TODO(#13146) acknowledgement of the URL-shadow concern is appropriate, and the test isolation rationale is sound.

Two issues to fix before merge:

  1. Stale class-level Javadoc — ExternalModelProfileActivationTest (compat): The class doc still reads "their profiles contribute no repositories" (line 34). That's now false for JDK/OS/activeByDefault-activated profiles — the very profiles this PR re-enables. Should be updated to reflect the new contract: file and property profiles contribute no repositories; legitimately-active (JDK/OS/activeByDefault) profiles do contribute their repositories.

  2. Stale class-level Javadoc — DefaultModelBuilderTest (impl): Same stale sentence at line 128 of that file.

  3. GAV typo in testActiveByDefaultProfileRepositoryHonored (impl): Sources.resolvedSource(..., "org.apache.maven.**test**:active-by-default-profile:1.0.0") — should be org.apache.maven.**tests** (plural) to match the fixture's declared <groupId>. The hint string doesn't affect profile evaluation, so the test passes regardless, but the inconsistency is confusing.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

.session(session)
.requestType(ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY)
.source(Sources.resolvedSource(
getPom("active-by-default-profile"), "org.apache.maven.test:active-by-default-profile:1.0.0"))

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.

⚠️ GAV typo: org.apache.maven.test (singular) does not match the fixture's <groupId>org.apache.maven.tests</groupId> (plural). The coordinate hint passed to resolvedSource does not drive profile selection, so the test still passes — but readers will be confused when they cross-reference the fixture. Please fix to "org.apache.maven.tests:active-by-default-profile:1.0.0".

Suggested change
getPom("active-by-default-profile"), "org.apache.maven.test:active-by-default-profile:1.0.0"))
getPom("active-by-default-profile"), "org.apache.maven.tests:active-by-default-profile:1.0.0"))

limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.1.0">
<groupId>org.apache.maven.tests</groupId>

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.

For consistency with the rest of the poms/factory/ fixtures and with how the impl test references this artifact, consider using org.apache.maven.test (without the trailing s) — or conversely, update the resolvedSource call to say org.apache.maven.tests. Either is fine; they just need to match.

- DefaultModelBuilderTest: update resolvedProfilesRequest() Javadoc
  (stale 'contribute no repositories'); fix active-by-default-profile
  resolvedSource GAV (org.apache.maven.test, matching fixture and
  existing test convention)
- active-by-default-profile.xml: fix groupId plural→singular to match
  the rest of the poms/factory fixtures and the test coordinate hint
- ExternalModelProfileActivationTest: update class-level Javadoc
  (stale 'contribute no repositories')

Found during review of apache#13155.

@gnodet-bot gnodet-bot 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.

All three findings from the prior review are addressed in the fixup commit (8011ebaf):

  • ✅ Stale Javadoc — ExternalModelProfileActivationTest (compat): class-level doc updated to reflect that legitimately-active profiles (JDK/OS/activeByDefault) do contribute repositories.
  • ✅ Stale Javadoc — DefaultModelBuilderTest (impl): same stale sentence corrected with the same contract description.
  • ✅ GAV groupId typo: fixture <groupId> corrected from org.apache.maven.tests → org.apache.maven.test, matching the resolvedSource coordinate in the test.

No new issues found. CI is fully green across all 22 matrix jobs (JDK 17/21/25, Ubuntu/macOS/Windows, unit + ITs). The fix is correct: VALIDATION_LEVEL_MINIMAL < VALIDATION_LEVEL_MAVEN_2_0 reliably exercises the externalModel=true branch, and BUILD_CONSUMER stripping is correctly left intact.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet
gnodet merged commit d00f5f0 into apache:maven-4.0.x Sep 16, 2026
22 checks passed
@gnodet
gnodet deleted the backport/13100-to-4.0.x branch September 16, 2026 18:57
gnodet added a commit that referenced this pull request Sep 17, 2026
…#13141) (#13156)

* Fix stale Javadoc and GAV typo in external-profile tests

- DefaultModelBuilderTest: update resolvedProfilesRequest() Javadoc
  (stale 'contribute no repositories'); fix active-by-default-profile
  resolvedSource GAV (org.apache.maven.test, matching fixture and
  existing test convention)
- active-by-default-profile.xml: fix groupId plural→singular to match
  the rest of the poms/factory fixtures and the test coordinate hint

Found during review of #13155.

* Revert wrong direction: keep org.apache.maven.test (no 's') in resolvedSource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants