diff --git a/src/it/projects/complete-multimodule-parent-pom-direct-dependencies/pom.xml b/src/it/projects/complete-multimodule-parent-pom-direct-dependencies/pom.xml index fbe03efd..8bc80557 100644 --- a/src/it/projects/complete-multimodule-parent-pom-direct-dependencies/pom.xml +++ b/src/it/projects/complete-multimodule-parent-pom-direct-dependencies/pom.xml @@ -14,6 +14,9 @@ org.codehaus.mojo flatten-maven-plugin + + direct + diff --git a/src/it/projects/inherit-parent-dependency/pom.xml b/src/it/projects/inherit-parent-dependency/pom.xml index 0396c371..094bd3f6 100644 --- a/src/it/projects/inherit-parent-dependency/pom.xml +++ b/src/it/projects/inherit-parent-dependency/pom.xml @@ -9,16 +9,4 @@ resolve-properties 0.0.1-SNAPSHOT - - verify - - - org.codehaus.mojo - flatten-maven-plugin - - all - - - - diff --git a/src/it/projects/parent-with-version-range/pom.xml b/src/it/projects/parent-with-version-range/pom.xml index 5125ba3d..4dd35939 100644 --- a/src/it/projects/parent-with-version-range/pom.xml +++ b/src/it/projects/parent-with-version-range/pom.xml @@ -1,25 +1,13 @@ - 4.0.0 + 4.0.0 - - org.codehaus.mojo.flatten.its - parent-deps - [0,2] - + + org.codehaus.mojo.flatten.its + parent-deps + [0,2] + parent-with-version-range 0.0.1-SNAPSHOT - - verify - - - org.codehaus.mojo - flatten-maven-plugin - - all - - - - diff --git a/src/main/java/org/codehaus/mojo/flatten/DirectDependenciesInheritanceAssembler.java b/src/main/java/org/codehaus/mojo/flatten/DirectDependenciesInheritanceAssembler.java index bcc878e4..db8fb195 100644 --- a/src/main/java/org/codehaus/mojo/flatten/DirectDependenciesInheritanceAssembler.java +++ b/src/main/java/org/codehaus/mojo/flatten/DirectDependenciesInheritanceAssembler.java @@ -18,12 +18,6 @@ */ package org.codehaus.mojo.flatten; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.util.HashMap; -import java.util.Map; - import org.apache.maven.model.Model; import org.apache.maven.model.ModelBase; import org.apache.maven.model.building.ModelBuildingRequest; @@ -31,6 +25,11 @@ import org.apache.maven.model.inheritance.DefaultInheritanceAssembler; import org.apache.maven.model.merge.MavenModelMerger; +import javax.inject.Named; +import javax.inject.Singleton; +import java.util.HashMap; +import java.util.Map; + /** * The DefaultInheritanceAssembler is encapsulating the InheritanceModelMerger. * The only way to override functionality needed is to define an own InheritanceAssembler @@ -144,7 +143,7 @@ public void merge(Model target, Model source, boolean sourceDominant, Map @Override protected void mergeModelBase_Dependencies( ModelBase target, ModelBase source, boolean sourceDominant, Map context) { - if (flattenDependencyMode == null || flattenDependencyMode == FlattenDependencyMode.direct) { + if (flattenDependencyMode == FlattenDependencyMode.direct) { return; } super.mergeModelBase_Dependencies(target, source, sourceDominant, context); diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenDependencyMode.java b/src/main/java/org/codehaus/mojo/flatten/FlattenDependencyMode.java index ef5fd2f0..46d289a2 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenDependencyMode.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenDependencyMode.java @@ -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 diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index 20342048..9e1b7fa3 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -19,31 +19,6 @@ * under the License. */ -import javax.inject.Inject; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.StringWriter; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Queue; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; @@ -99,6 +74,30 @@ import org.xml.sax.SAXException; import org.xml.sax.ext.DefaultHandler2; +import javax.inject.Inject; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Queue; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * This MOJO realizes the goal flatten that generates the flattened POM and {@link #isUpdatePomFile() * potentially updates the POM file} so that the current {@link MavenProject}'s {@link MavenProject#getFile() file} @@ -339,8 +338,16 @@ public class FlattenMojo extends AbstractFlattenMojo { * * * direct - * 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.

+ *

This was the default mode with Flatten Plugin in versions 1.4.0 up to 1.6.0. + * + * + * + * inherited + *

Flatten the dependency versions, including inherited dependencies from a parent module

+ *

This is the default mode and compatible with Flatten Plugin prior to 1.2.0, this mode was called direct between versions 1.2.0 and 1.3.0.

+ * + * * * all *

Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up @@ -1225,7 +1232,9 @@ protected void createFlattenedDependencies(Model effectiveModel, List projectDependencies = currentProject.getOriginalModel().getDependencies(); List 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 {