Class SmartProjectComparator
java.lang.Object
org.apache.maven.lifecycle.internal.builder.multithreaded.SmartProjectComparator
Smart project comparator that orders projects based on critical path analysis.
Projects with longer downstream dependency chains are prioritized to maximize
parallel execution efficiency.
The algorithm calculates a weight for each project as: weight = 1 + max(downstream_project_weights)
Projects are then sorted by weight in descending order, ensuring that projects with longer dependency chains are built first. When projects have the same weight, they are ordered by project ID for deterministic results.
Example:
Consider projects with dependencies: A → B → D, A → C → D
- Project D: weight = 1 (no downstream dependencies)
- Project B: weight = 2 (1 + max(D=1))
- Project C: weight = 2 (1 + max(D=1))
- Project A: weight = 3 (1 + max(B=2, C=2))
Build order: A (weight=3), then B and C (weight=2, ordered by project ID), then D (weight=1)
If projects have identical weights and IDs, the order is deterministic but may not preserve the original declaration order.
- Since:
- 4.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the comparator for ordering projects by critical path priority.longgetProjectWeight(MavenProject project) Gets the calculated weight for a project, representing its dependency chain length.
-
Constructor Details
-
SmartProjectComparator
-
-
Method Details
-
getComparator
Gets the comparator for ordering projects by critical path priority.- Returns:
- comparator that orders projects with longer dependency chains first
-
getProjectWeight
Gets the calculated weight for a project, representing its dependency chain length.- Parameters:
project- the project- Returns:
- the project's weight (higher means longer dependency chain)
-