[MNG-7720] Wrong build order of forked projects (#1040)

The original fix MNG-7672 matched the "scope" but missed the "order". `project.collectedProjects` are in order as loaded (POM order), is not topologically sorted.

Fix is to use DAG of projects, ask for downstream projects (will return more then we need but sorted) and narrow that list to only contain collected projects.

---

https://issues.apache.org/jira/browse/MNG-7720
This commit is contained in:
Tamas Cservenak 2023-03-08 09:04:35 +01:00 committed by GitHub
parent bec19ec41d
commit 1ffd68b802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -90,7 +90,11 @@ public class LifecycleDependencyResolver {
public static List<MavenProject> getProjects(MavenProject project, MavenSession session, boolean aggregator) {
if (aggregator && project.getCollectedProjects() != null) {
return getProjectAndSubModules(project).collect(Collectors.toList());
List<MavenProject> 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<MavenProject> 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(