1919 * under the License.
2020 */
2121
22- import java .util .Queue ;
2322import org .apache .maven .artifact .Artifact ;
2423import org .apache .maven .artifact .factory .ArtifactFactory ;
2524import org .apache .maven .artifact .repository .ArtifactRepository ;
5150import org .apache .maven .plugins .annotations .Mojo ;
5251import org .apache .maven .plugins .annotations .Parameter ;
5352import org .apache .maven .plugins .annotations .ResolutionScope ;
53+ import org .apache .maven .project .DefaultProjectBuildingRequest ;
5454import org .apache .maven .project .MavenProject ;
55- import org .apache .maven .shared .dependency .tree .DependencyNode ;
56- import org .apache .maven .shared .dependency .tree .DependencyTreeBuilder ;
57- import org .apache .maven .shared .dependency .tree .DependencyTreeBuilderException ;
58- import org .apache .maven .shared .dependency .tree .traversal .DependencyNodeVisitor ;
55+ import org .apache .maven .project .ProjectBuildingRequest ;
56+ import org .apache .maven .shared .dependency .graph .DependencyGraphBuilder ;
57+ import org .apache .maven .shared .dependency .graph .DependencyGraphBuilderException ;
58+ import org .apache .maven .shared .dependency .graph .DependencyNode ;
59+ import org .apache .maven .shared .dependency .graph .traversal .DependencyNodeVisitor ;
5960import org .apache .maven .shared .transfer .dependencies .resolve .DependencyResolver ;
6061import org .codehaus .mojo .flatten .cifriendly .CiInterpolator ;
6162import org .codehaus .mojo .flatten .model .resolution .FlattenModelResolver ;
8990import java .util .LinkedList ;
9091import java .util .List ;
9192import java .util .Properties ;
93+ import java .util .Queue ;
9294import java .util .Set ;
9395
9496/**
@@ -224,7 +226,7 @@ public class FlattenMojo
224226 @ Parameter ( property = "updatePomFile" )
225227 private Boolean updatePomFile ;
226228
227- /** The {@link ArtifactRepository} required to resolve POM using {@link #modelBuilder} . */
229+ /** The {@link ArtifactRepository} required to resolve POM. */
228230 @ Parameter ( defaultValue = "${localRepository}" , readonly = true , required = true )
229231 private ArtifactRepository localRepository ;
230232
@@ -284,7 +286,7 @@ public class FlattenMojo
284286 * </tr>
285287 * <tr>
286288 * <td>bom</td>
287- * <td>Like {@link # ossrh} but additionally keeps {@link Model#getDependencyManagement() dependencyManagement} and
289+ * <td>Like <code> ossrh</code> but additionally keeps {@link Model#getDependencyManagement() dependencyManagement} and
288290 * {@link Model#getProperties() properties}. Especially it will keep the {@link Model#getDependencyManagement()
289291 * dependencyManagement} <em>as-is</em> without resolving parent influences and import-scoped dependencies. This is
290292 * useful if your POM represents a <a href=
@@ -343,7 +345,7 @@ public class FlattenMojo
343345 private FlattenDependencyMode flattenDependencyMode ;
344346
345347 /**
346- * The ArtifactFactory required to resolve POM using {@link #modelBuilder} .
348+ * The ArtifactFactory required to resolve POM.
347349 */
348350 // Neither ArtifactFactory nor DefaultArtifactFactory tells what to use instead
349351 @ Component
@@ -371,7 +373,7 @@ public class FlattenMojo
371373 private DependencyResolver dependencyResolver ;
372374
373375 @ Component ( hint = "default" )
374- private DependencyTreeBuilder dependencyTreeBuilder ;
376+ private DependencyGraphBuilder dependencyGraphBuilder ;
375377
376378 @ Component (role = ArtifactDescriptorReader .class )
377379 private ArtifactDescriptorReader artifactDescriptorReader ;
@@ -1080,19 +1082,21 @@ private void createFlattenedDependenciesDirect( List<Dependency> projectDependen
10801082 *
10811083 * @param projectDependencies is the effective POM {@link Model}'s current dependencies
10821084 * @param flattenedDependencies is the {@link List} where to add the collected {@link Dependency dependencies}.
1083- * @throws DependencyTreeBuilderException
1085+ * @throws DependencyGraphBuilderException
10841086 * @throws ArtifactDescriptorException
10851087 */
10861088 private void createFlattenedDependenciesAll ( List <Dependency > projectDependencies , List <Dependency > flattenedDependencies )
1087- throws DependencyTreeBuilderException , ArtifactDescriptorException
1089+ throws ArtifactDescriptorException , DependencyGraphBuilderException
10881090 {
10891091 final Queue <DependencyNode > dependencyNodeLinkedList = new LinkedList <>();
10901092 final Set <String > processedDependencies = new HashSet <>();
10911093
10921094 final Artifact projectArtifact = this .project .getArtifact ();
10931095
1094- final DependencyNode dependencyNode = this .dependencyTreeBuilder .buildDependencyTree (this .project ,
1095- this .localRepository , null );
1096+ ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest ( session .getProjectBuildingRequest () );
1097+ buildingRequest .setProject ( project );
1098+
1099+ final DependencyNode dependencyNode = this .dependencyGraphBuilder .buildDependencyGraph ( buildingRequest , null );
10961100
10971101 dependencyNode .accept (new DependencyNodeVisitor ()
10981102 {
@@ -1110,10 +1114,6 @@ private void createFlattenedDependenciesAll( List<Dependency> projectDependencie
11101114 return false ;
11111115 }
11121116 }
1113- if (node .getState () != DependencyNode .INCLUDED )
1114- {
1115- return false ;
1116- }
11171117 if (node .getArtifact ().isOptional ())
11181118 {
11191119 return false ;
0 commit comments