Skip to content

Fix getProjects() mutating project artifact versions (#268) - #284

Merged
slachiewicz merged 2 commits into
masterfrom
fix/issue-268-no-mutation-of-artifacts
Oct 28, 2026
Merged

slachiewicz merged 2 commits into
masterfrom
fix/issue-268-no-mutation-of-artifacts

Conversation

@elharo

@elharo elharo commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #268

Problem

getProjects() called artifact.setVersion(artifact.getBaseVersion()) on the
artifact instances obtained from getAllDependencies(). For the process
mojo, getAllDependencies() returns project.getArtifacts() directly, so this
mutated the live, shared Artifact objects — stripping timestamped snapshot
versions down to their base version as a side effect that later build steps
observe. The mutation only happened when a template referenced
$projects/$projectsSortedByOrganization.

Fix

Instead of mutating the shared instance, build a new DefaultArtifact from the
artifact's base version (carrying over file, resolution state and the other
coordinates) and use that only for the project model building. The original
artifacts in project.getArtifacts() are left untouched.

Test

New unit test testProjectsDoesNotMutateProjectArtifactVersions: adds a
snapshot artifact to the project, invokes getProjects(), and asserts the
artifact's version is still 1.0-SNAPSHOT (and that the same instance remains
in project.getArtifacts()). Verified the test fails without the fix
(expected:<[1.0-SNAPSHOT]> but was:<[Test Version]>) and passes with it.
Full mvn verify (incl. spotless/checkstyle/RAT) passes.

@elharo
elharo requested a review from reanguiano August 2, 2026 14:07
@elharo
elharo requested a review from sparsick August 18, 2026 12:45
@slachiewicz
slachiewicz force-pushed the fix/issue-268-no-mutation-of-artifacts branch 3 times, most recently from b6308ec to 1550be5 Compare October 28, 2026 14:01
@slachiewicz
slachiewicz force-pushed the fix/issue-268-no-mutation-of-artifacts branch from 1550be5 to 987daf5 Compare October 28, 2026 14:46
@slachiewicz
slachiewicz merged commit f371fb9 into master Oct 28, 2026
23 checks passed
@slachiewicz
slachiewicz deleted the fix/issue-268-no-mutation-of-artifacts branch October 28, 2026 15:23
@github-actions github-actions Bot added this to the 3.3.1 milestone Oct 28, 2026
@github-actions

Copy link
Copy Markdown

@slachiewicz Please assign appropriate label to PR according to the type of change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getProjects() mutates the project's resolved Artifact versions (side effect)

2 participants