Skip to content

Deduplicate filtered dependency graph #2489

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

Conversation

alzimmermsft
Copy link
Contributor

@alzimmermsft alzimmermsft commented Jun 17, 2025

Fixes #2487

Adds logic to de-duplicate the list of MavenProjects being returned by FilteredProjectDependencyGraph.applyFilter to prevent building the same project multiple times in a parallel, multi-module build.

A lengthy comment is added to the main change explaining a situation where the same project could be added multiple times, which I'll repeat here.

Given the following, simplified, aggregate POM where project E has a direct dependency on all of A, B, C, and D.

<modules>
  <module>A</module>
  <module>B</module>
  <module>C</module>
  <module>D</module>
  <module>E</module>
<modules>

If a parallel build was using --pl A,C,E if FilteredProjectDependencyGraph.applyFilter was called with the aggregate POM's MavenProjects (A, B, C, D, and E) and non-transitive and downstream dependencies were being filtered for, the following would happen.

  1. A, C, and E would be added to the filtered result as they're in the whitelist.
  2. B and D would be scanned for their downstream projects as they aren't in the whitelist and transitive is false.
  3. The result of B and D's scanning would find project E as it depends on both projects.

This would result in project E being added to filtered three separate times. Once for being in the whitelist itself and twice more for being a downstream project of two projects not in the whitelist.

I also added a small bit of logic to short circuit being distincting filtered when it would effectively be a wasted no-op, when there is zero or one project in the list.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@slawekjaranowski
Copy link
Member

look ok for me @cstamas @gnodet please also look

We need do the same in master.

@slawekjaranowski slawekjaranowski added the bug Something isn't working label Jun 17, 2025
@slawekjaranowski slawekjaranowski added this to the 3.9.11 milestone Jun 17, 2025
@cstamas
Copy link
Member

cstamas commented Jun 18, 2025

Thank you for contribution! 🍻

@alzimmermsft
Copy link
Contributor Author

Glad to help @cstamas!

If this is also an issue in master, I'm happy to file a PR against it as well.

@cstamas
Copy link
Member

cstamas commented Jun 18, 2025

Feel free to do so! Let the beer flow... 😄

@slawekjaranowski slawekjaranowski merged commit 5107f47 into apache:maven-3.9.x Jun 18, 2025
18 checks passed
cstamas pushed a commit that referenced this pull request Jun 19, 2025
cstamas added a commit to cstamas/maven that referenced this pull request Jun 19, 2025
@alzimmermsft alzimmermsft deleted the DeduplicateFilteredDependencyGraph branch June 19, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants