-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.9.x] [MNG-7720] Wrong build order of forked projects #1038
[3.9.x] [MNG-7720] Wrong build order of forked projects #1038
Conversation
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: 48cac1c --- https://issues.apache.org/jira/browse/MNG-7720
return getProjectAndSubModules(project).collect(Collectors.toList()); | ||
List<MavenProject> downstreamProjects = session.getProjectDependencyGraph() | ||
.getDownstreamProjects(project, true); // sorted but more than needed | ||
List<MavenProject> collectedProjects = project.getCollectedProjects(); // not sorted but what we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be getProjectAndSubModules(project).collect(Collectors.toList())
instead of project.getCollectedProjects()
, else the content will be very different.
The first one will return the project and all its submodules (recursively), while the second will just return the modules of the current project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so only 1 level... right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot confirm this statement with 3.8.7: https://github.com/apache/maven-doxia-sitetools/pull/94/files#r1136260250
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean we don't need to recurse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is what is expected here? I debugged with Maven SCM and all modules were in that list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I misread the code at
maven/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Lines 626 to 631 in 8150c62
List<MavenProject> modules = new ArrayList<>(); | |
noErrors = build(results, modules, projectIndex, interimResult.modules, request, profilesXmls, session) | |
&& noErrors; | |
projects.addAll(modules); | |
projects.add(project); |
Reading more closely, the projects
list will contain all submodules recursively...
private static Stream<MavenProject> getProjectAndSubModules(MavenProject project) { | ||
return Stream.concat( | ||
Stream.of(project), | ||
project.getCollectedProjects().stream().flatMap(LifecycleDependencyResolver::getProjectAndSubModules)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note how this method is recursive...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
getProjectAndSubModules(project).collect(Collectors.toList()); // not sorted but what we need | ||
return downstreamProjects.stream() | ||
.filter(projectAndSubmodules::contains) | ||
.collect(Collectors.toList()); // sorted what we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returned list should contain the project
instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can propose the following which may be slightly easier to read
List<MavenProject> projectAndSubmodules =
getProjectAndSubModules(project).collect(Collectors.toList());
return Stream.concat(
Stream.of(project),
session.getProjectDependencyGraph().getDownstreamProjects(project, true).stream())
.filter(projectAndSubmodules::contains)
.collect(Collectors.toList());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what I figured out yesterday as well
Liquibase build started failing when we switcthed to Maven 3.9.0 , it's a similar issue using the aggregate-jar javadoc goal. Here is a failed build link: https://github.com/liquibase/liquibase/actions/runs/4196586092/jobs/7277765171 . |
As NOTHING guarantees that none is null, it is really just a "detail" of current DefaultProjectBuilder code (implementation).
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: 48cac1c
https://issues.apache.org/jira/browse/MNG-7720