-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Disable consumer POM flattening by default and add an opt-in feature #11347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gnodet
merged 8 commits into
apache:master
from
gnodet:gh-11346-consumer-pom-flatten-control
Oct 31, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
67f11aa
Add consumer POM flattening control feature
gnodet 6c5cd2a
Update consumer POM flattening feature and integration tests
gnodet 8f4587a
Do not change the pom description
gnodet 5ee477e
Fix ITs requiring flattening
gnodet 381776a
Fix MavenITmng6957BuildConsumer
gnodet 42674fa
More fixes
gnodet fac3c7d
Remove unrelated javadoc change
gnodet 2a98a59
Remove unrelated javadoc change
gnodet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,6 +463,18 @@ public final class Constants { | |
| @Config(type = "java.lang.Boolean", defaultValue = "true") | ||
| public static final String MAVEN_CONSUMER_POM = "maven.consumer.pom"; | ||
|
|
||
| /** | ||
| * User property for controlling consumer POM flattening behavior. | ||
| * When set to <code>true</code> (default), consumer POMs are flattened by removing | ||
| * dependency management and keeping only direct dependencies with transitive scopes. | ||
| * When set to <code>false</code>, consumer POMs preserve dependency management | ||
|
Comment on lines
+468
to
+470
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This says |
||
| * like parent POMs, allowing dependency management to be inherited by consumers. | ||
| * | ||
| * @since 4.1.0 | ||
| */ | ||
| @Config(type = "java.lang.Boolean", defaultValue = "false") | ||
| public static final String MAVEN_CONSUMER_POM_FLATTEN = "maven.consumer.pom.flatten"; | ||
|
|
||
| /** | ||
| * User property for controlling "maven personality". If activated Maven will behave | ||
| * like the previous major version, Maven 3. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...ite/src/test/java/org/apache/maven/it/MavenITgh11346DependencyManagementOverrideTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.it; | ||
|
|
||
| import java.io.File; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.maven.api.Constants; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * This is a test set for dependency management override scenarios when | ||
| * consumer POM flattening is disabled (maven.consumer.pom.flatten=false). | ||
| * | ||
| * Scenario: | ||
| * - A 1.0 depends on B 1.0 and manages C to 1.2 | ||
| * - B 1.0 has no dependencies | ||
| * - B 2.0 depends on C 1.1 | ||
| * - D depends on A 1.0 and manages B to 2.0 | ||
| * | ||
| * Question: Does D depend on C, and which version? | ||
| * | ||
| * Expected behavior when flattening is disabled: D should get C 1.2 (from A's dependency management), | ||
| * not C 1.1 (from B 2.0's dependency), because A's dependency | ||
| * management applies to D's transitive dependencies. | ||
| * | ||
| * @see <a href="https://github.com/apache/maven/issues/11346">gh-11346</a> | ||
| */ | ||
| public class MavenITgh11346DependencyManagementOverrideTest extends AbstractMavenIntegrationTestCase { | ||
|
|
||
| /** | ||
| * Verify that when consumer POM flattening is disabled, dependency management | ||
| * from intermediate dependencies applies to the consumer's transitive dependencies. | ||
| * This test uses -Dmaven.consumer.pom.flatten=false to enable dependency management | ||
| * inheritance from transitive dependencies. | ||
| * | ||
| * @throws Exception in case of failure | ||
| */ | ||
| @Test | ||
| public void testDependencyManagementOverride() throws Exception { | ||
| File testDir = extractResources("/gh-11346-dependency-management-override"); | ||
|
|
||
| Verifier verifier = newVerifier(testDir.getAbsolutePath()); | ||
| verifier.deleteArtifacts("org.apache.maven.its.mng.depman"); | ||
| // Test with dependency manager transitivity disabled instead of consumer POM flattening | ||
| verifier.addCliArgument("-D" + Constants.MAVEN_CONSUMER_POM_FLATTEN + "=false"); | ||
| verifier.addCliArgument("verify"); | ||
| verifier.execute(); | ||
| verifier.verifyErrorFreeLog(); | ||
|
|
||
| // Check module D's classpath | ||
| List<String> dClasspath = verifier.loadLines("module-d/target/classpath.txt"); | ||
|
|
||
| // D should have A 1.0 | ||
| assertTrue(dClasspath.contains("module-a-1.0.jar"), "D should depend on A 1.0: " + dClasspath); | ||
|
|
||
| // D should have B 2.0 (managed by D) | ||
| assertTrue(dClasspath.contains("module-b-2.0.jar"), "D should depend on B 2.0 (managed by D): " + dClasspath); | ||
| assertFalse(dClasspath.contains("module-b-1.0.jar"), "D should not depend on B 1.0: " + dClasspath); | ||
|
|
||
| // D should have C 1.2 (from A's dependency management) | ||
| // A's dependency management of C to 1.2 should apply to D | ||
| assertTrue( | ||
| dClasspath.contains("module-c-1.2.jar"), | ||
| "D should depend on C 1.2 (A's dependency management should apply): " + dClasspath); | ||
| assertFalse( | ||
| dClasspath.contains("module-c-1.1.jar"), | ||
| "D should not depend on C 1.1 (should be managed to 1.2): " + dClasspath); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDependencyManagementOverrideNoTransitive() throws Exception { | ||
| File testDir = extractResources("/gh-11346-dependency-management-override"); | ||
|
|
||
| Verifier verifier = newVerifier(testDir.getAbsolutePath()); | ||
| verifier.deleteArtifacts("org.apache.maven.its.mng.depman"); | ||
| // Test with dependency manager transitivity disabled instead of consumer POM flattening | ||
| verifier.addCliArgument("-D" + Constants.MAVEN_CONSUMER_POM_FLATTEN + "=false"); | ||
| verifier.addCliArgument("-D" + Constants.MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY + "=false"); | ||
| verifier.addCliArgument("verify"); | ||
| verifier.execute(); | ||
| verifier.verifyErrorFreeLog(); | ||
|
|
||
| // Check module D's classpath | ||
| List<String> dClasspath = verifier.loadLines("module-d/target/classpath.txt"); | ||
|
|
||
| // D should have A 1.0 | ||
| assertTrue(dClasspath.contains("module-a-1.0.jar"), "D should depend on A 1.0: " + dClasspath); | ||
|
|
||
| // D should have B 2.0 (managed by D) | ||
| assertTrue(dClasspath.contains("module-b-2.0.jar"), "D should depend on B 2.0 (managed by D): " + dClasspath); | ||
| assertFalse(dClasspath.contains("module-b-1.0.jar"), "D should not depend on B 1.0: " + dClasspath); | ||
|
|
||
| // D should have C 1.1 as the resolver is not transitive | ||
| assertFalse( | ||
| dClasspath.contains("module-c-1.2.jar"), | ||
| "D should depend on C 1.2 (A's dependency management should apply): " + dClasspath); | ||
| assertTrue( | ||
| dClasspath.contains("module-c-1.1.jar"), | ||
| "D should not depend on C 1.1 (should be managed to 1.2): " + dClasspath); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...core-it-suite/src/test/resources/gh-11346-dependency-management-override/module-a/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.maven.its.mng.depman</groupId> | ||
| <artifactId>test</artifactId> | ||
| <version>0.1</version> | ||
| </parent> | ||
|
|
||
| <artifactId>module-a</artifactId> | ||
| <version>1.0</version> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <!-- A manages C to version 1.2 --> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng.depman</groupId> | ||
| <artifactId>module-c</artifactId> | ||
| <version>1.2</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <!-- A depends on B 1.0 --> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng.depman</groupId> | ||
| <artifactId>module-b</artifactId> | ||
| <version>1.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that this can only be controlled by a
-Dflag? So you cannot easily enable flattening on specific modules. I guess you could add-Dto.mvn/maven.configif you wished to enable flattening on all modules in a given reactor (such as one Git repository). Has any thought been given to controlling this mode based on a flag set in the POM itself (if that is even possible)? Or as a configuration option to theinstallmojo, etc.?