Skip to content

Fix/13390 dependency profile property activation - #13401

Closed
Utkarsh-rwt wants to merge 6 commits into
apache:masterfrom
Utkarsh-rwt:fix/13390-dependency-profile-property-activation
Closed

Utkarsh-rwt wants to merge 6 commits into
apache:masterfrom
Utkarsh-rwt:fix/13390-dependency-profile-property-activation

Conversation

@Utkarsh-rwt

@Utkarsh-rwt Utkarsh-rwt commented Oct 11, 2026 •

Copy link
Copy Markdown

Summary

Note : copilot helped me to write this pr
Fixes #13390.

This change prevents properties declared in a dependency POM from activating property-based profiles in that same POM during external model building.

Background

Maven 3.10.0 introduced external dependency-POM profile hardening through the changes for #13084, implemented in #13112 and backported through #13114.

That change introduced an external ProfileActivationContext which suppressed consumer user properties and merged the dependency model's project properties into the system-property lookup.

The merge caused a dependency POM such as:

<properties>
  <example.enable.extra>true</example.enable.extra>
</properties>

to activate its own property-based profile:

<activation>
  <property>
    <name>example.enable.extra</name>
  </property>
</activation>

POM-defined properties should not act as profile activation properties for the same dependency POM.

Scope

This PR addresses the POM-local property activation bug from #13390.

It does not change the intentional external-model hardening for file-based profiles, and it does not address the separate compatibility question from #13347 regarding whether -Dmaven.model.dependencyInterpolation.full=true should restore user-property profile activation.

Changes

  • Removed dependency POM-local properties from the external system-property lookup.
  • Preserved activation based on actual system properties, including platform properties such as java.version and os.name.
  • Continued suppressing consumer user properties (-D) when evaluating dependency POM profiles.
  • Preserved negated-property/default-on profiles, such as RESTEasy's !resteasy.dependencies.eap pattern.
  • Applied the fix consistently to:
    • compat/maven-model-builder
    • impl/maven-impl

Tests

Updated and added regression coverage in both model-building implementations.

Compat model builder

Updated:

compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ExternalModelProfileActivationTest.java

The tests verify that:

  • A positive property profile backed by the dependency POM's own <properties> remains inactive.
  • System-property profile activation still works.
  • Consumer user-property activation remains suppressed.
  • File-based activation remains suppressed.
  • JDK activation still works.
  • Negated-property/default-on activation still works.

Maven implementation model builder

Updated:

impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java

Added an assertion that a dependency POM's declared property does not activate its own profile.

Updated:

impl/maven-impl/src/test/resources/poms/factory/resolved-model-with-profiles.xml

Added a POM-local property and a profile activated by that property to reproduce #13390.

Validation

The full reactor command was executed:

mvn -DdistributionTargetDir="$PWD/target/apache-maven-test-dist" clean verify

The full reactor reached maven-core, but failed in four unrelated existing ProjectModelResolverTest cases because the test repository returned no matching versions for ranges such as (,2.0) and [1,).

The affected tests were run independently:

mvn -pl compat/maven-model-builder,impl/maven-impl \
  -Dtest=ExternalModelProfileActivationTest,DefaultModelBuilderTest \
  -Dsurefire.failIfNoSpecifiedTests=false test

Result:

  • impl/maven-impl: DefaultModelBuilderTest — 40 passed
  • compat/maven-model-builder: DefaultModelBuilderTest — 3 passed
  • compat/maven-model-builder: ExternalModelProfileActivationTest — 10 passed
  • Total affected tests: 53 passed, 0 failures, 0 errors
- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).

Utkarsh-rwt and others added 3 commits October 9, 2026 18:14
Prevent dependency POM-local properties from activating their own profiles while preserving external model sandbox behavior and negated default-on profiles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

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

Two findings on this PR.


Metadata suggestions

  • Milestone: 4.1.0
  • Backport to maven-3.10.x: ⚠️ Missing — the compat-layer behavioral change likely needs a matching backport.

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

mergedSystemProperties = Collections.unmodifiableMap(merged);
}
return mergedSystemProperties;
return delegate.getSystemProperties();

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.

⚠️ Compat-layer behavioral change — backport needed?

externalActivationContext() previously merged POM <properties> into the system-properties map so that property-based profiles in dependency POMs could still fire. This PR removes that merging: getSystemProperties() now delegates directly, stripping POM-declared properties from the sandbox entirely.

That is an intentional behaviour reversal in the compat layer (compat/maven-model-builder). The compat layer is supposed to mirror Maven 3 semantics as closely as possible. If maven-3.10.x still carries the old merging logic, this change should be backported there too — or the PR should explicitly justify why the compat-layer behaviour intentionally diverges from Maven 3.

Comment on lines +1665 to +1666
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection,

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.

💬 Minor: Awkward comment wrapping — "reach injection," dangles

The new lines read:

// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection,
// and stripping their repositories would break the established

// reach injection, is a dangling continuation, making the sentence hard to parse. Consider collapsing the two lines:

Suggested change
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection,
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection, and stripping their repositories would break the established

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Utkarsh-rwt

Copy link
Copy Markdown
Author

Thanks for pointing this out. I confirmed that maven-3.10.x still contains the same compat-layer behavior and therefore needs the fix as well.

I will keep this PR targeted at Maven 4.1.0 and prepare a separate backport PR against maven-3.10.x, including the compat implementation and regression test.

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

Re-reviewing after the clarification commit.

The backport concern raised in the previous review (compat-layer behavioural change in maven-3.10.x) remains unanswered — please address it or explicitly document why the compat layer should diverge from Maven 3 semantics.


Metadata suggestions

  • Milestone: 4.1.1
  • Backport to maven-3.10.x: ⚠️ Still missing — origin/maven-3.10.x carries the merging logic at lines 544–551 in the compat DefaultModelBuilder.

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

Prevent dependency POM-local properties from reaching external condition activation and add regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Utkarsh-rwt

Copy link
Copy Markdown
Author

I agree the external sandbox must prevent dependency POM-local properties from influencing both property-based and condition-based profile activation.

Updated in commit e11d322:

  • getSystemProperty() no longer exposes dependency POM-local properties.
  • getModelProperty() now returns null in the external activation context.
  • Added regression coverage for a condition-based profile using a POM-local property.

Validation passed:

  • DefaultModelBuilderTest: 40 passed
  • Compat DefaultModelBuilderTest: 3 passed
  • ExternalModelProfileActivationTest: 10 passed
  • Total: 53 passed, 0 failures, 0 errors

I will also address the remaining Maven 3.10.x compat-layer backport separately.

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

Re-review of commit e11d322.

The getModelProperty() sandbox gap is confirmed closed — the new commit makes it return null in the DefaultProfileActivationContext sandbox, so POM-declared properties cannot drive condition expressions via ConditionProfileActivator. ✅

Two prior findings remain unaddressed:

  1. Dangling comment wrap (line 1665–1666 below) — the // reach injection, continuation hangs on its own line; prior suggestion still not applied.

  2. Backport to maven-3.10.x still missing — the compat/maven-model-builder behavioral change (removing POM property merging from the system-property sandbox) diverges from maven-3.10.x. Author acknowledged the gap and committed to a backport PR, but it hasn't appeared. Please prepare the backport before or alongside this PR merging.

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

Comment on lines +1665 to +1666
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection, and stripping their repositories would break the established

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.

Dangling comment continuation — // reach injection, wraps to its own line, making the sentence awkward to parse. Prior suggestion still not applied.

Suggested change
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
// reach injection, and stripping their repositories would break the established
// profiles (JDK/OS/activeByDefault and negated-property default-on profiles) reach injection,
// and stripping their repositories would break the established

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@gnodet gnodet 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 PR fixes the property-based profile activation regression in master, but a backport to maven-3.10.x is missing.

Issue #13390 explicitly states:

The behavior is still present in maven-3.10.x.

The fix targets compat/maven-model-builder and impl/maven-impl on master only. No corresponding maven-3.10.x PR has appeared. The author acknowledged this gap in prior comments ("I confirmed that maven-3.10.x still contains the same compat-layer behavior and therefore needs the fix as well") but the backport has not been submitted yet.

Please submit a companion PR targeting maven-3.10.x before this is merged, or confirm the branch policy that makes a backport unnecessary.

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

@Utkarsh-rwt

Copy link
Copy Markdown
Author

The companion Maven 3.10.x backport has now been submitted:

#13402

It targets maven-3.10.x and updates the compat-layer implementation to remove dependency POM-local properties from the external profile activation system-property lookup.

The backport also updates the regression test:

maven-model-builder/src/test/java/org/apache/maven/model/building/ResolvedDependencyProfileActivationTest.java

Validation passed:

10 tests passed, 0 failures, 0 errors

@gnodet

gnodet commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Fully automatic review from Claude Code

Closing in favor of #13450 (master), #13451 (maven-3.10.x), and #13452 (maven-4.0.x), which address the same issue with equivalent changes plus updated Javadoc across all interfaces and additional regression tests (jruby-style #13390 and resteasy-style #13084 non-regression).

Thank you for working on this — the analysis in the PR description is solid.

@gnodet gnodet closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven 3.10.0 activates dependency POM profiles using the POM’s own properties

2 participants