apache / apache/maven-remote-resources-plugin

Perf: triggers a Maven model build for every dependency artifact

Open
#270 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
17
Forks
18
Avg merge
6h 5m
Merged PRs (30d)
5

Description

## 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`

```java
public Object internalGet(String key) {
Object result = super.internalGet(key);
if (result == null && key != null && key.startsWith(KEY_PROJECTS) && containsKey(key)) {
List 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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java, especially internalGet() at lines 770-783 and getProjects() at lines 533-556. Reproduce the cost of a template referencing $projects, then trace the ProjectBuildingRequest and projectBuilder.build(artifact, req) calls. Done means avoiding unnecessary model builds, reusing matching reactor projects where appropriate, and not computing the organization-sorted map unless it is referenced.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.