Skip to content

Fix #12774: skip consumer POM re-attachment on repeated task segments - #12916

Merged
gnodet merged 2 commits into
apache:maven-4.0.xfrom
gnodet:fix/12774
Aug 30, 2026
Merged

Fix #12774: skip consumer POM re-attachment on repeated task segments#12916
gnodet merged 2 commits into
apache:maven-4.0.xfrom
gnodet:fix/12774

Conversation

@gnodet

@gnodet gnodet commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make ConsumerPomArtifactTransformer.injectTransformedArtifacts() idempotent by checking if a consumer POM artifact (classifier=consumer, type=pom) is already attached before calling addAttachedArtifact()
  • Prevents the duplicate "Building ..." header and artifact '...:pom:consumer:...' already attached, replacing previous instance warning when running multiple task segments (e.g. mvn package compiler:help)
  • Add unit test verifying that a second invocation does not duplicate the attached artifact

Fixes #12774

Test plan

  • New unit test injectTransformedArtifactsTwiceShouldNotDuplicate verifies idempotency
  • Manual verification: mvn package compiler:help no longer produces the warning

🤖 Generated with Claude Code

…gments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Aug 29, 2026
@gnodet gnodet added the bug Something isn't working label Aug 29, 2026
@gnodet
gnodet marked this pull request as ready for review August 29, 2026 15:59

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct and minimal fix that makes injectTransformedArtifacts() idempotent by guarding against duplicate consumer POM attachment.

One low-severity optimization opportunity noted inline.

Positive observations:

  • TransformedArtifact already handles POM-change detection lazily via SHA1 checksumming in mayUpdate(), so skipping re-attachment is safe — the already-attached artifact will still pick up source POM changes on the next getFile() call.
  • The matching criteria (getClassifier() + getType()) on Maven's Artifact interface is correct for this context.

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

deferDeleteFile(consumer);

project.addAttachedArtifact(createConsumerPomArtifact(project, consumer, session));
boolean alreadyAttached = project.getAttachedArtifacts().stream()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: The idempotency check here is placed after the temp file creation and deferDeleteFile() registration (lines 87-90). On repeated invocations where the consumer POM is already attached, a new temp file is created on disk, registered for deferred deletion, but never used.

Consider hoisting the alreadyAttached check to the top of the if (Features.consumerPom(...)) block, before creating the temp file. This would avoid unnecessary I/O on repeated invocations. The files are cleaned up by @PreDestroy doDeleteFiles() so this is not a leak, just wasteful work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to apply this improvement before merging as we had some performance issue with local repository in rc6 or do you want to apply it in a separate PR/later version?

Avoid unnecessary I/O on repeated invocations by checking whether
the consumer POM is already attached before creating a temp file
and registering it for deferred deletion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delta review — checking new commit 9515783 ("Hoist alreadyAttached check before temp file creation").

Previous finding resolved: The alreadyAttached check is now the first statement inside the if (Features.consumerPom(...)) block, and all temp file creation / deferDeleteFile() / addAttachedArtifact calls are wrapped inside if (!alreadyAttached). No unnecessary I/O on repeated invocations.

A new regression test injectTransformedArtifactsTwiceShouldNotDuplicate verifies the idempotency behavior — clean, well-structured test.

No new issues introduced.

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

@gnodet
gnodet merged commit 888682d into apache:maven-4.0.x Aug 30, 2026
22 checks passed
gnodet added a commit that referenced this pull request Aug 30, 2026
…#12916) (#12956)

* Fix #12774: skip consumer POM re-attachment on repeated task segments



* Hoist alreadyAttached check before temp file creation

Avoid unnecessary I/O on repeated invocations by checking whether
the consumer POM is already attached before creating a temp file
and registering it for deferred deletion.



---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants