Skip to content

fix: use Maven 4 consumer POM instead of build POM#51

Merged
mhoffrog merged 1 commit intomavenplugins:masterfrom
mariuszs:fix/maven4-consumer-pom
Apr 15, 2026
Merged

fix: use Maven 4 consumer POM instead of build POM#51
mhoffrog merged 1 commit intomavenplugins:masterfrom
mariuszs:fix/maven4-consumer-pom

Conversation

@mariuszs
Copy link
Copy Markdown
Contributor

@mariuszs mariuszs commented Mar 15, 2026

Summary

  • Maven 4 generates a consumer POM (attached artifact with classifier consumer, type pom) containing resolved versions and model 4.0.0
  • The plugin currently always uses mavenProject.getFile() (the build POM) which contains unresolved ${revision} and model 4.1.0
  • This causes Maven Central Portal to reject deployments with "Failed to associate file with coordinates" because it cannot parse the 4.1.0 model POM

The fix

In ProjectUtilsImpl:

  • Detect consumer POM among attached artifacts
  • Use it as ProjectArtifactMetadata instead of the build POM
  • Filter it from attached artifacts list to prevent it appearing as a separate -consumer.pom file in the bundle

Backwards compatible — without consumer POM (Maven 3 projects) behavior is unchanged.

Test plan

  • shouldNotIncludeConsumerPomAsSeparateArtifact — verifies consumer POM is used as main POM metadata and filtered from artifacts
  • shouldWorkNormallyWithoutConsumerPom — verifies Maven 3 backwards compatibility

Related

  • MNG-8584 — Maven4: Central publishing readiness

Summary by CodeRabbit

  • Bug Fixes

    • Improved Maven 4 consumer POM handling: plugin now prefers a consumer POM when present, excludes it from the artifact list, and substitutes consumer-POM signatures for build-POM signatures to avoid duplicate artifacts.
  • Tests

    • Added tests validating consumer POM detection, artifact filtering, and fallback behavior when absent.
    • Added Mockito inline mock-maker test configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 15, 2026

Warning

Rate limit exceeded

@mariuszs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6b48713-e7e8-4f7c-af00-011a21fe10ec

📥 Commits

Reviewing files that changed from the base of the PR and between 592a31d and 18e13eb.

📒 Files selected for processing (3)
  • src/main/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImpl.java
  • src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java
  • src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker

Walkthrough

Adds Maven 4 consumer POM detection and preference in ProjectUtilsImpl: consumer POMs are used as the primary POM when present, filtered from attached-artifact lists, and consumer-POM signatures substitute build-POM signatures. A new test class and Mockito inline config validate the behavior.

Changes

Cohort / File(s) Summary
Consumer POM Handling
src/main/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImpl.java
Introduces Optional-based consumer POM support: findConsumerPom(), findConsumerPomSignature(), isBuildPomSignature(), isConsumerPom(). Uses findConsumerPom(...).orElse(mavenProject.getFile()) for primary POM selection; filters consumer POM from attached artifacts and substitutes consumer-POM signature files where applicable.
Tests & Test Config
src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java, src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
Adds test suite validating consumer POM handling (exclusion from artifacts, signature substitution, and fallback behavior) and enables Mockito inline mock maker for tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: switching from the build POM to the consumer POM for Maven 4 compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java (1)

84-115: Add a test for the attached-only fallback branch.

Current tests don’t exercise the file == null && !attachedArtifacts.isEmpty() path in ProjectUtilsImpl, where POM file selection can regress independently.

Also applies to: 121-137

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java`
around lines 84 - 115, Add a new test (or extend
shouldNotIncludeConsumerPomAsSeparateArtifact) to exercise the attached-only
fallback branch in ProjectUtilsImpl.getArtifacts by creating a MavenProject
whose main Artifact has file == null but attachedArtifacts is non-empty (include
a consumer POM with classifier "consumer" and another attached artifact like
sources), then call projectUtils.getArtifacts(project, artifactFactory) and
assert the consumer POM is not returned as a separate ArtifactWithFile and only
the expected artifacts (e.g., sources and main jar replacement behavior) are
present; this targets the code path where file == null &&
!attachedArtifacts.isEmpty() so POM selection doesn't regress.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImpl.java`:
- Around line 161-163: The fallback branch is using mavenProject.getFile() and
bypasses the consumer-POM selected by findConsumerPom; capture the result of
findConsumerPom(mavenProject) into a pomFile variable and ensure that
artifact.addMetadata(new ProjectArtifactMetadata(...)) and the attached-only
fallback both use that same pomFile (instead of calling mavenProject.getFile()
directly) so the consumer-aware POM is always used (refer to findConsumerPom,
mavenProject, artifact.addMetadata, and ProjectArtifactMetadata to locate the
affected logic).

In
`@src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java`:
- Around line 81-82: Update the Javadoc comment in the
ProjectUtilsImplConsumerPomTest class: remove the stale phrase "Currently FAILS
- " from the comment that says "Currently FAILS - consumer POM leaks into the
artifact list." (or reword the whole sentence) so the test class comment
reflects the fixed state; locate the comment block in
ProjectUtilsImplConsumerPomTest and edit the Javadoc to a neutral or accurate
description of the test purpose.

---

Nitpick comments:
In
`@src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java`:
- Around line 84-115: Add a new test (or extend
shouldNotIncludeConsumerPomAsSeparateArtifact) to exercise the attached-only
fallback branch in ProjectUtilsImpl.getArtifacts by creating a MavenProject
whose main Artifact has file == null but attachedArtifacts is non-empty (include
a consumer POM with classifier "consumer" and another attached artifact like
sources), then call projectUtils.getArtifacts(project, artifactFactory) and
assert the consumer POM is not returned as a separate ArtifactWithFile and only
the expected artifacts (e.g., sources and main jar replacement behavior) are
present; this targets the code path where file == null &&
!attachedArtifacts.isEmpty() so POM selection doesn't regress.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd603dae-7249-4af9-82ee-75a85d45dc61

📥 Commits

Reviewing files that changed from the base of the PR and between 8143cf5 and bf1dbe5.

📒 Files selected for processing (3)
  • src/main/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImpl.java
  • src/test/java/org/sonatype/central/publisher/plugin/utils/ProjectUtilsImplConsumerPomTest.java
  • src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker

@mariuszs mariuszs force-pushed the fix/maven4-consumer-pom branch 2 times, most recently from 592a31d to 30da9e0 Compare March 15, 2026 19:25
Maven 4 generates a consumer POM (classifier="consumer", type="pom")
that contains resolved versions and model 4.0.0 - this is what should
be deployed to Maven Central. Previously the plugin always used the
build POM (mavenProject.getFile()) which contains unresolved
${revision} and model 4.1.0, causing Central Portal to reject the
deployment with "Failed to associate file with coordinates".

The fix:
- Detect consumer POM among attached artifacts
- Use it as ProjectArtifactMetadata instead of build POM
- Filter consumer POM artifacts from attached artifacts list
- Swap build POM GPG signature with consumer POM signature

Backwards compatible - without consumer POM (Maven 3) behavior
is unchanged.
@mariuszs mariuszs force-pushed the fix/maven4-consumer-pom branch from 30da9e0 to 18e13eb Compare March 15, 2026 19:26
@mhoffrog mhoffrog self-assigned this Apr 15, 2026
@mhoffrog mhoffrog added bug Something isn't working java Pull requests that update Java code tests Pull requests that update integration tests labels Apr 15, 2026
@mhoffrog mhoffrog merged commit 97f4835 into mavenplugins:master Apr 15, 2026
1 check passed
@mhoffrog
Copy link
Copy Markdown
Contributor

@mariuszs Many THANKS for your contribution! 👍

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

Labels

bug Something isn't working java Pull requests that update Java code tests Pull requests that update integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants