diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java index 699d70477e..973b798c61 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java @@ -90,7 +90,11 @@ public class LifecycleDependencyResolver { public static List getProjects(MavenProject project, MavenSession session, boolean aggregator) { if (aggregator && project.getCollectedProjects() != null) { - return getProjectAndSubModules(project).collect(Collectors.toList()); + List projectAndSubmodules = + getProjectAndSubModules(project).collect(Collectors.toList()); // not sorted but what we need + return session.getProjects().stream() // sorted all + .filter(projectAndSubmodules::contains) + .collect(Collectors.toList()); // sorted and filtered to what we need } else { return Collections.singletonList(project); } @@ -99,7 +103,10 @@ public class LifecycleDependencyResolver { private static Stream getProjectAndSubModules(MavenProject project) { return Stream.concat( Stream.of(project), - project.getCollectedProjects().stream().flatMap(LifecycleDependencyResolver::getProjectAndSubModules)); + project.getCollectedProjects() == null + ? Stream.empty() + : project.getCollectedProjects().stream() + .flatMap(LifecycleDependencyResolver::getProjectAndSubModules)); } public void resolveProjectDependencies(