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

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.

Related commit: 48cac1c003

---

https://issues.apache.org/jira/browse/MNG-7720
This commit is contained in:
Tamas Cservenak 2023-03-08 09:03:33 +01:00 committed by GitHub
parent 528cea3ad9
commit 57acdd41b4
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(