Skip to content

Commit

Permalink
Fix Issue#377 Regression: parent dependencies missing in flattened pom
Browse files Browse the repository at this point in the history
... 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
  • Loading branch information
hkampbjorn committed Jan 7, 2025
1 parent 8bd8956 commit 681dee3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 38 deletions.
15 changes: 15 additions & 0 deletions src/it/mrm/repository/parent-transitive-deps-1.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-transitive-dep</artifactId>
<version>1</version>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenDependencyMode>direct</flattenDependencyMode>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
14 changes: 1 addition & 13 deletions src/it/projects/inherit-parent-dependency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,9 @@

<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-deps</artifactId>
<artifactId>parent-transitive-dep</artifactId>
<version>1</version>
</parent>
<artifactId>resolve-properties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenDependencyMode>all</flattenDependencyMode>
</configuration>
</plugin>
</plugins>
</build>
</project>
24 changes: 6 additions & 18 deletions src/it/projects/parent-with-version-range/pom.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
<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">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-deps</artifactId>
<version>[0,2]</version>
</parent>
<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-deps</artifactId>
<version>[0,2]</version>
</parent>

<artifactId>parent-with-version-range</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenDependencyMode>all</flattenDependencyMode>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void merge(Model target, Model source, boolean sourceDominant, Map<?, ?>
@Override
protected void mergeModelBase_Dependencies(
ModelBase target, ModelBase source, boolean sourceDominant, Map<Object, Object> context) {
if (flattenDependencyMode == null || flattenDependencyMode == FlattenDependencyMode.direct) {
if (flattenDependencyMode == FlattenDependencyMode.direct) {
return;
}
super.mergeModelBase_Dependencies(target, source, sourceDominant, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
*/
public enum FlattenDependencyMode {
/**
* Flatten only the direct dependency versions. This is the default mode and compatible with
* Flatten Plugin prior to 1.2.0.
* Flatten only the direct dependency versions, excluding inherited dependencies from a parent module.
*/
direct,

/**
* Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up
* Flatten dependencies, including inherited dependencies from a parent module.
* This is the default mode and compatible with Flatten Plugin prior to 1.2.0.
*/
inherited,

/**
* Flatten both direct, inherited and transitive dependencies. This will examine the full dependency tree, and pull up
* all transitive dependencies as a direct dependency, and setting their versions appropriately.
*
* This is recommended if you are releasing a library that uses dependency management to manage dependency
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,16 @@ public class FlattenMojo extends AbstractFlattenMojo {
* </thead><tbody>
* <tr>
* <td>direct</td>
* <td>Flatten only the direct dependency versions.
* This is the default mode and compatible with Flatten Plugin prior to 1.2.0.</td>
* <td><p>Flatten only the direct dependency versions, excluding inherited dependencies from a parent module.</p>
* <p>This was the default mode with Flatten Plugin in versions 1.4.0 up to 1.6.0.
* </td>
* </tr>
* <tr>
* <td>inherited</td>
* <td><p>Flatten the dependency versions, including inherited dependencies from a parent module</p>
* <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>
* </td>
* </tr>
* <tr>
* <td>all</td>
* <td><p>Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up
Expand Down Expand Up @@ -1217,7 +1225,9 @@ protected void createFlattenedDependencies(Model effectiveModel, List<Dependency
// List<Dependency> projectDependencies = currentProject.getOriginalModel().getDependencies();
List<Dependency> projectDependencies = effectiveModel.getDependencies();

if (flattenDependencyMode == null | flattenDependencyMode == FlattenDependencyMode.direct) {
if (flattenDependencyMode == null
|| flattenDependencyMode == FlattenDependencyMode.direct
|| flattenDependencyMode == FlattenDependencyMode.inherited) {
createFlattenedDependenciesDirect(projectDependencies, flattenedDependencies);
} else if (flattenDependencyMode == FlattenDependencyMode.all) {
try {
Expand Down

0 comments on commit 681dee3

Please sign in to comment.