You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Utkarsh-rwt (via GitHub)" <gi...@apache.org> on 2026/10/11 06:21:00 UTC

[PR] Fix/13390 dependency profile property activation [maven]

Utkarsh-rwt opened a new pull request, #13401:
URL: https://github.com/apache/maven/pull/13401

   
   ## 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:
   ```xml
   <properties>
     <example.enable.extra>true</example.enable.extra>
   </properties>
   ```
   to activate its own property-based profile:
   ```xml
   <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:
   ```bash
   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:
   ```bash
   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**
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "Utkarsh-rwt (via GitHub)" <gi...@apache.org>.
Utkarsh-rwt commented on PR #13401:
URL: https://github.com/apache/maven/pull/13401#issuecomment-6106892051

   The companion Maven 3.10.x backport has now been submitted:
   
   apache/maven#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:
   ```text
   10 tests passed, 0 failures, 0 errors


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13401:
URL: https://github.com/apache/maven/pull/13401#issuecomment-6106196500

   <!-- license-declaration-check -->
   ### ⚠️ License declaration missing
   
   The pull request description must contain at least one of the following lines with a **checked** box (`[x]`):
   
   ```markdown
   - [ ] 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)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   ```
   
   This comment will be hidden automatically once the description is fixed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed pull request #13401: Fix/13390 dependency profile property activation
URL: https://github.com/apache/maven/pull/13401


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13401:
URL: https://github.com/apache/maven/pull/13401#issuecomment-6154401545

   _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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13401:
URL: https://github.com/apache/maven/pull/13401#discussion_r4240692920


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java:
##########
@@ -1654,21 +1654,16 @@ private List<Profile> getActiveProfiles(
                     // A model resolved to satisfy dependency resolution -- a dependency POM
                     // itself, or one of its parents, reached transitively -- evaluates profiles
                     // against a sandboxed activation context.  The sandbox:
-                    //  - merges model properties into system property lookups (so POM-declared
-                    //    <properties> drive activation via the existing property lookup chain),
+                    //  - does not expose model properties through system-property lookups, so
+                    //    dependency POMs cannot activate their own property-based profiles,
                     //  - suppresses user properties (consumer -D flags must not activate
                     //    dependency profiles — they were not set for that artifact),
                     //  - disables file existence checks (publisher paths don't exist here).
-                    // Model properties are merged into system properties rather than adding
-                    // a separate lookup step in PropertyProfileActivator, because changing the
-                    // activator would affect ALL profile evaluations (including the build's own
-                    // project) and cause unintended profile activation when a POM declares a
-                    // property that matches a profile's activation condition.
                     // File-activated profiles are pre-filtered (not just sandboxed) because
                     // returning false from exists() would incorrectly activate <missing> profiles.
                     // Repository stripping is intentionally omitted: only legitimately-active
-                    // profiles (JDK/OS/activeByDefault and POM-property-gated) 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

Review Comment:
   Dangling comment continuation — `// reach injection,` wraps to its own line, making the sentence awkward to parse. Prior suggestion still not applied.
   
   ```suggestion
                       // profiles (JDK/OS/activeByDefault and negated-property default-on profiles) reach injection,
                       // and stripping their repositories would break the established
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13401:
URL: https://github.com/apache/maven/pull/13401#discussion_r4240601993


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultProfileActivationContext.java:
##########
@@ -389,18 +387,9 @@ public boolean isProfileInactive(String profileId) {
                 return DefaultProfileActivationContext.this.isProfileInactive(profileId);
             }
 
-            /**
-             * System property lookup with model property fallback.
-             * System properties take precedence; model properties fill in as a fallback
-             * so POM-declared values drive property-activated profiles in external models.
-             */
             @Override
             public String getSystemProperty(String key) {
-                String value = DefaultProfileActivationContext.this.getSystemProperty(key);
-                if (value == null) {
-                    value = DefaultProfileActivationContext.this.getModelProperty(key);
-                }
-                return value;
+                return DefaultProfileActivationContext.this.getSystemProperty(key);
             }

Review Comment:
   ⚠️ **Incomplete sandbox — `ConditionProfileActivator` still sees POM-declared properties**
   
   `getSystemProperty()` is now correctly sandboxed (line 392), but the adjacent `getModelProperty()` override (line 402–403) still delegates to the parent context without restriction:
   
   ```java
   @Override
   public String getModelProperty(String key) {
       return DefaultProfileActivationContext.this.getModelProperty(key);
   }
   ```
   
   `ConditionProfileActivator.doGetProperty()` queries `context.getModelProperty(name)` first (line 189), before falling back to `getSystemProperty`. In the external-model sandbox this means `<condition>` expressions in dependency POMs can still see POM-declared `<properties>`, making `<condition>`-based profile activation in external builds **not** symmetric with `<properties>`-based activation.
   
   If the intent is that no POM-declared property should influence external-model profile activation, `getModelProperty()` should either return `null` or be blocked here too. If the asymmetry is intentional, it should be documented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #13401:
URL: https://github.com/apache/maven/pull/13401#discussion_r4240539222


##########
compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java:
##########
@@ -554,26 +542,9 @@ public List<String> getInactiveProfileIds() {
                 return delegate.getInactiveProfileIds();
             }
 
-            /**
-             * System properties merged with project properties (system wins on conflict).
-             * This makes POM-declared properties visible to the PropertyProfileActivator
-             * without modifying the activator's lookup chain for non-external models.
-             * The merged map is computed once and cached to avoid repeated allocations.
-             */
             @Override
             public Map<String, String> getSystemProperties() {
-                if (mergedSystemProperties != null) {
-                    return mergedSystemProperties;
-                }
-                Map<String, String> projectProps = delegate.getProjectProperties();
-                if (projectProps == null || projectProps.isEmpty()) {
-                    mergedSystemProperties = Collections.unmodifiableMap(delegate.getSystemProperties());
-                } else {
-                    Map<String, String> merged = new HashMap<>(projectProps);
-                    merged.putAll(delegate.getSystemProperties()); // system wins
-                    mergedSystemProperties = Collections.unmodifiableMap(merged);
-                }
-                return mergedSystemProperties;
+                return delegate.getSystemProperties();

Review Comment:
   ⚠️ **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.



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java:
##########
@@ -1654,20 +1654,16 @@ private List<Profile> getActiveProfiles(
                     // A model resolved to satisfy dependency resolution -- a dependency POM
                     // itself, or one of its parents, reached transitively -- evaluates profiles
                     // against a sandboxed activation context.  The sandbox:
-                    //  - merges model properties into system property lookups (so POM-declared
-                    //    <properties> drive activation via the existing property lookup chain),
+                    //  - does not expose model properties through system-property lookups, so
+                    //    dependency POMs cannot activate their own property-based profiles,
                     //  - suppresses user properties (consumer -D flags must not activate
                     //    dependency profiles — they were not set for that artifact),
                     //  - disables file existence checks (publisher paths don't exist here).
-                    // Model properties are merged into system properties rather than adding
-                    // a separate lookup step in PropertyProfileActivator, because changing the
-                    // activator would affect ALL profile evaluations (including the build's own
-                    // project) and cause unintended profile activation when a POM declares a
-                    // property that matches a profile's activation condition.
                     // File-activated profiles are pre-filtered (not just sandboxed) because
                     // returning false from exists() would incorrectly activate <missing> profiles.
                     // Repository stripping is intentionally omitted: only legitimately-active
-                    // profiles (JDK/OS/activeByDefault and POM-property-gated) reach injection,
+                    // profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
+                    // reach injection,

Review Comment:
   💬 **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:
   
   ```suggestion
                       // profiles (JDK/OS/activeByDefault and negated-property default-on profiles)
                       // reach injection, and stripping their repositories would break the established
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "Utkarsh-rwt (via GitHub)" <gi...@apache.org>.
Utkarsh-rwt commented on PR #13401:
URL: https://github.com/apache/maven/pull/13401#issuecomment-6106416172

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/13390 dependency profile property activation [maven]

Posted by "Utkarsh-rwt (via GitHub)" <gi...@apache.org>.
Utkarsh-rwt commented on PR #13401:
URL: https://github.com/apache/maven/pull/13401#issuecomment-6106628608

    I agree the external sandbox must prevent dependency POM-local properties from influencing both property-based and condition-based profile activation.
   
   Updated in commit e11d322b42:
   
   - `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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org