Skip to content

Commit b622639

Browse files
hkampbjornslawekjaranowski
authored andcommitted
Fix Issue#377 Regression: parent dependencies missing in flattened pom
... since 1.4.0. Introduce a new "inherited" flatten dependency mode that includes the inherited dependencies like "direct" did in 1.3.0. And make this the new default behaviour bringing it back to 1.3.0 and before
1 parent 600e7a0 commit b622639

File tree

7 files changed

+47
-38
lines changed

7 files changed

+47
-38
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.codehaus.mojo.flatten.its</groupId>
4+
<artifactId>parent-transitive-dep</artifactId>
5+
<version>1</version>
6+
<packaging>pom</packaging>
7+
8+
<dependencies>
9+
<dependency>
10+
<groupId>org.codehaus.mojo.flatten.its</groupId>
11+
<artifactId>core</artifactId>
12+
<version>3.2.1</version>
13+
</dependency>
14+
</dependencies>
15+
</project>

src/it/projects/complete-multimodule-parent-pom-direct-dependencies/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<plugin>
1515
<groupId>org.codehaus.mojo</groupId>
1616
<artifactId>flatten-maven-plugin</artifactId>
17+
<configuration>
18+
<flattenDependencyMode>direct</flattenDependencyMode>
19+
</configuration>
1720
</plugin>
1821
</plugins>
1922
</build>

src/it/projects/inherit-parent-dependency/pom.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,9 @@
44

55
<parent>
66
<groupId>org.codehaus.mojo.flatten.its</groupId>
7-
<artifactId>parent-deps</artifactId>
7+
<artifactId>parent-transitive-dep</artifactId>
88
<version>1</version>
99
</parent>
1010
<artifactId>resolve-properties</artifactId>
1111
<version>0.0.1-SNAPSHOT</version>
12-
<build>
13-
<defaultGoal>verify</defaultGoal>
14-
<plugins>
15-
<plugin>
16-
<groupId>org.codehaus.mojo</groupId>
17-
<artifactId>flatten-maven-plugin</artifactId>
18-
<configuration>
19-
<flattenDependencyMode>all</flattenDependencyMode>
20-
</configuration>
21-
</plugin>
22-
</plugins>
23-
</build>
2412
</project>
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
3+
<modelVersion>4.0.0</modelVersion>
44

5-
<parent>
6-
<groupId>org.codehaus.mojo.flatten.its</groupId>
7-
<artifactId>parent-deps</artifactId>
8-
<version>[0,2]</version>
9-
</parent>
5+
<parent>
6+
<groupId>org.codehaus.mojo.flatten.its</groupId>
7+
<artifactId>parent-deps</artifactId>
8+
<version>[0,2]</version>
9+
</parent>
1010

1111
<artifactId>parent-with-version-range</artifactId>
1212
<version>0.0.1-SNAPSHOT</version>
13-
<build>
14-
<defaultGoal>verify</defaultGoal>
15-
<plugins>
16-
<plugin>
17-
<groupId>org.codehaus.mojo</groupId>
18-
<artifactId>flatten-maven-plugin</artifactId>
19-
<configuration>
20-
<flattenDependencyMode>all</flattenDependencyMode>
21-
</configuration>
22-
</plugin>
23-
</plugins>
24-
</build>
2513
</project>

src/main/java/org/codehaus/mojo/flatten/DirectDependenciesInheritanceAssembler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void merge(Model target, Model source, boolean sourceDominant, Map<?, ?>
144144
@Override
145145
protected void mergeModelBase_Dependencies(
146146
ModelBase target, ModelBase source, boolean sourceDominant, Map<Object, Object> context) {
147-
if (flattenDependencyMode == null || flattenDependencyMode == FlattenDependencyMode.direct) {
147+
if (flattenDependencyMode == FlattenDependencyMode.direct) {
148148
return;
149149
}
150150
super.mergeModelBase_Dependencies(target, source, sourceDominant, context);

src/main/java/org/codehaus/mojo/flatten/FlattenDependencyMode.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@
2727
*/
2828
public enum FlattenDependencyMode {
2929
/**
30-
* Flatten only the direct dependency versions. This is the default mode and compatible with
31-
* Flatten Plugin prior to 1.2.0.
30+
* Flatten only the direct dependency versions, excluding inherited dependencies from a parent module.
3231
*/
3332
direct,
3433

3534
/**
36-
* Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up
35+
* Flatten dependencies, including inherited dependencies from a parent module.
36+
* This is the default mode and compatible with Flatten Plugin prior to 1.2.0.
37+
*/
38+
inherited,
39+
40+
/**
41+
* Flatten both direct, inherited and transitive dependencies. This will examine the full dependency tree, and pull up
3742
* all transitive dependencies as a direct dependency, and setting their versions appropriately.
3843
*
3944
* This is recommended if you are releasing a library that uses dependency management to manage dependency

src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,16 @@ public class FlattenMojo extends AbstractFlattenMojo {
339339
* </thead><tbody>
340340
* <tr>
341341
* <td>direct</td>
342-
* <td>Flatten only the direct dependency versions.
343-
* This is the default mode and compatible with Flatten Plugin prior to 1.2.0.</td>
342+
* <td><p>Flatten only the direct dependency versions, excluding inherited dependencies from a parent module.</p>
343+
* <p>This was the default mode with Flatten Plugin in versions 1.4.0 up to 1.6.0.
344+
* </td>
345+
* </tr>
346+
* <tr>
347+
* <td>inherited</td>
348+
* <td><p>Flatten the dependency versions, including inherited dependencies from a parent module</p>
349+
* <p>This is the default mode and compatible with Flatten Plugin prior to 1.2.0, this mode was called <tt>direct</tt> between versions 1.2.0 and 1.3.0.</p>
350+
* </td>
351+
* </tr>
344352
* <tr>
345353
* <td>all</td>
346354
* <td><p>Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up
@@ -1217,7 +1225,9 @@ protected void createFlattenedDependencies(Model effectiveModel, List<Dependency
12171225
// List<Dependency> projectDependencies = currentProject.getOriginalModel().getDependencies();
12181226
List<Dependency> projectDependencies = effectiveModel.getDependencies();
12191227

1220-
if (flattenDependencyMode == null | flattenDependencyMode == FlattenDependencyMode.direct) {
1228+
if (flattenDependencyMode == null
1229+
|| flattenDependencyMode == FlattenDependencyMode.direct
1230+
|| flattenDependencyMode == FlattenDependencyMode.inherited) {
12211231
createFlattenedDependenciesDirect(projectDependencies, flattenedDependencies);
12221232
} else if (flattenDependencyMode == FlattenDependencyMode.all) {
12231233
try {

0 commit comments

Comments
 (0)