[MNG-6357] Dependency order should be nearest first - #281
Conversation
|
Please review this patch. Tested it and seems to solve: |
|
Looks good at first sight. This code deserves a unittest, that's better than relying on plugins. I don't think the unittest is too hard to write. |
|
@rfscholte We have more serious problems that introducing fancy Java 8 features. |
| DependencyFilter filter ) | ||
| { | ||
| Map<Integer, List<org.apache.maven.artifact.Artifact>> artifactsByDepth = | ||
| new TreeMap<Integer, List<org.apache.maven.artifact.Artifact>>(); |
There was a problem hiding this comment.
you can use diamond <>. It is Java 1.7 feature.
There was a problem hiding this comment.
If i open IDEA, it shows me these issues related to Java version.
| Map<Integer, List<org.apache.maven.artifact.Artifact>> artifactsByDepth = | ||
| new TreeMap<Integer, List<org.apache.maven.artifact.Artifact>>(); | ||
|
|
||
| ArrayList<org.apache.maven.artifact.Artifact> firstLevelArtifacts = |
There was a problem hiding this comment.
aaa, Collection or List better than ArrayList.
| new TreeMap<Integer, List<org.apache.maven.artifact.Artifact>>(); | ||
|
|
||
| ArrayList<org.apache.maven.artifact.Artifact> firstLevelArtifacts = | ||
| new ArrayList<org.apache.maven.artifact.Artifact>( nodes.size() ); |
| List<org.apache.maven.artifact.Artifact> artifactsCurrentDepth = artifactsByDepth.get( currentDepth ); | ||
| if ( artifactsCurrentDepth == null ) | ||
| { | ||
| artifactsCurrentDepth = new ArrayList<org.apache.maven.artifact.Artifact>(); |
|
The merge conflict is pretty straight-forward to fix (it's a simple collision in the pom.xml). Would love to see this go in! Happy to provide a new PR if that's preferable |
|
Per https://maven.apache.org/download.cgi Maven 4.x requires JDK 8. What is needed to move this PR forward? |
|
Resolve #7501 |
gnodet
left a comment
There was a problem hiding this comment.
AI Code Review — PR #281
Verdict:
This PR changes RepositoryUtils.toArtifacts() to produce artifacts ordered by dependency tree depth (breadth-first / nearest-first) instead of depth-first. The approach using a TreeMap<Integer, List<Artifact>> keyed by depth is logically correct and addresses a legitimate issue (MNG-6357).
However, the PR is 4+ years stale and cannot merge.
Findings
| # | Severity | File | Details |
|---|---|---|---|
| 1 | 🔴 High | RepositoryUtils.java |
Stale path — File moved to impl/maven-core/... by MNG-8346. Merge state is CONFLICTING. |
| 2 | 🔴 High | RepositoryUtilsTest.java |
Test file conflict — A RepositoryUtilsTest.java already exists on master (added by commit 25c80d8ece). The PR's test class would need to be merged into the existing test file. Also, @author tags were removed from the codebase (commit 0b3246381d). |
Behavioral concern
This change affects every caller of RepositoryUtils.toArtifacts() — including plugin classpath construction and project artifact resolution. While breadth-first ordering is arguably more correct, any code that implicitly depends on the current depth-first ordering could break. The PR description acknowledges that IT-3813 "does not apply any longer," suggesting awareness of this risk. A full integration test run is essential after rebasing.
Recommendation
If MNG-6357 is still desired: (1) rebase onto current master, (2) merge tests into the existing RepositoryUtilsTest.java, (3) remove @author tag, (4) run the full integration test suite to validate no regressions.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Reviewed 3 PRs: apache#144 (COMMENT), apache#1125 (COMMENT), apache#281 (COMMENT). 36 total reviews posted. ~23 PRs remaining. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Let me know if this patch is still needed to do the recommended changes. |
gnodet
left a comment
There was a problem hiding this comment.
This PR (MNG-6357, opened August 2019) changes dependency ordering to breadth-first (nearest-first). After 7 years, the codebase has evolved significantly, making this PR unmergeable in its current state:
-
Target files relocated: All three changed files target
maven-core/which was relocated toimpl/maven-core/by MNG-8346. GitHub confirms the merge state is DIRTY/CONFLICTING. -
Extensive code drift:
RepositoryUtils.javahas been modified by 21+ commits since August 2019, including two full reformats (MNG-7601/MNG-7650), a Resolver 2.0 upgrade (MNG-7994), and a package move toorg.apache.maven.impl(MNG-8508). The PR's diff is based on a 2019 snapshot that no longer applies. -
Missing required fallback: The original issue MNG-6357 explicitly states "there should be a system property to get the original order, just in case somebody needs it." This PR unconditionally replaces the ordering with no toggle or escape hatch.
Additionally, the recent comment from the author (July 2026) asks "Let me know if this patch is still needed." Given that MNG-6357 links to MNG-7852 ("is superseded by") and Maven 4.0 has undergone a major reorganization, the maintainers may want to clarify whether this issue is still relevant in Maven 4.x.
If the change is still desired, a fresh PR against impl/maven-core/ with current code style, the system-property fallback, and integration tests would be needed.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
|
Hi @gnodet, I rebased the code. |
elharo
left a comment
There was a problem hiding this comment.
What is this actually doing?
I'm a hard no on anything that changes the dependency graphs Maven builds. That's a compatibility disaster. It is very likely the dependency resolution algorithm Maven chose decades ago was the wrong choice, but that choice is made and cannot be changed now.
| try { | ||
| return parser.parseLiteral(dependencyGraph); | ||
| } catch (IOException e) { | ||
| fail("Failed the parsing of the dependency node graph"); |
| import org.eclipse.aether.graph.Dependency; | ||
| import org.eclipse.aether.graph.DependencyFilter; | ||
| import org.eclipse.aether.graph.DependencyNode; | ||
| import org.eclipse.aether.internal.test.util.DependencyGraphParser; |
There was a problem hiding this comment.
shouldn't depend on internal class from another package
| */ | ||
| BFS(RepositoryUtils::toArtifactsBFS), | ||
| /** | ||
| * Breadth-first traversal of the dependency graph, using a List of List to store artifacts by depth, and a stack to keep the dependency trail. This is the new behavior. |
| } | ||
| } | ||
|
|
||
| private static void toArtifactsBFS( |
There was a problem hiding this comment.
why do we have several different BFS methods? what's different about them? Better names or comments or both are needed.
There was a problem hiding this comment.
I left only one now
| } | ||
| } | ||
|
|
||
| public static void toArtifactsBFS2( |
There was a problem hiding this comment.
This is public and the others are private?
There was a problem hiding this comment.
fixed to private
401cb38 to
8019391
Compare
Save the artifacts temporarily in a Map ordered by tree depth, and only
after finishing iterating over the dependency tree are the artifacts
added to the collection in depth order.
Note: IT-core test needs to be added replacing IT 3813 which does not apply any longer for a maven version containing this change.
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] - Fixes bug in ApproximateQuantiles,where you replace
MNG-XXXwith the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verifyto make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
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.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.