Summary
Referencing $projects (or $projectsSortedByOrganization) in a template triggers getProjects(), which performs a full projectBuilder.build(...) for every dependency artifact — not just the reactor projects.
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:770-783, 533-556
public Object internalGet(String key) {
Object result = super.internalGet(key);
if (result == null && key != null && key.startsWith(KEY_PROJECTS) && containsKey(key)) {
List<MavenProject> projects = getProjects();
put(KEY_PROJECTS, projects);
put(KEY_PROJECTS_ORGS, getProjectsSortedByOrganization(projects));
return super.internalGet(key);
}
return result;
}
getProjects() builds a ProjectBuildingRequest and calls projectBuilder.build(artifact, req) for each artifact in the (filtered) dependency set (:541-556), then sorts the results.
Impact
- For projects with hundreds of dependencies,
$projects costs hundreds of expensive model builds (POM fetch + parent chain + property resolution each).
- The computation is eager for both
projects and projectsSortedByOrganization even when a template references only one of them.
- It is recomputed whenever a new
projects* key is accessed before caching settles, though the first computation is the dominant cost.
The lazy mechanism is intentional, but the cost per use is high and worth documenting or optimizing (e.g. only build models for artifacts not already in the reactor, or cache across executions).
Suggested fix
Consider reusing reactor projects from mavenSession.getProjects() when the artifact matches, building only genuinely external artifacts, and computing the org-sorted map only when actually referenced.
Summary
Referencing
$projects(or$projectsSortedByOrganization) in a template triggersgetProjects(), which performs a fullprojectBuilder.build(...)for every dependency artifact — not just the reactor projects.src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:770-783, 533-556getProjects()builds aProjectBuildingRequestand callsprojectBuilder.build(artifact, req)for each artifact in the (filtered) dependency set (:541-556), then sorts the results.Impact
$projectscosts hundreds of expensive model builds (POM fetch + parent chain + property resolution each).projectsandprojectsSortedByOrganizationeven when a template references only one of them.projects*key is accessed before caching settles, though the first computation is the dominant cost.The lazy mechanism is intentional, but the cost per use is high and worth documenting or optimizing (e.g. only build models for artifacts not already in the reactor, or cache across executions).
Suggested fix
Consider reusing reactor projects from
mavenSession.getProjects()when the artifact matches, building only genuinely external artifacts, and computing the org-sorted map only when actually referenced.