Skip to content

fix: fix addParentPoms=true causes repositories to be ignored.#1585

Merged
slawekjaranowski merged 3 commits into
apache:masterfrom
k-wall:issue-1028
May 20, 2026
Merged

fix: fix addParentPoms=true causes repositories to be ignored.#1585
slawekjaranowski merged 3 commits into
apache:masterfrom
k-wall:issue-1028

Conversation

@k-wall
Copy link
Copy Markdown
Contributor

@k-wall k-wall commented Feb 4, 2026

Fix for #1028 - If addParentPoms is true, the plugin fails to respect any remote repositories declared in the POM leading to a build failure when resolving artefacts that do not exist in Maven Central.

When the failure occurs, it fails as follows. (Note: In this case the org.apache.kafka:kafka-clients:pom:4.2.0 is available in staging repo which is referenced in the project's POM).

[INFO] Artifact org.apache.kafka:kafka-clients:pom:4.2.0 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [central (https://repo.maven.apache.org/maven2, default, releases)]
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/kafka/kafka-clients/4.2.0/kafka-clients-4.2.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.347 s
[INFO] Finished at: 2026-02-03T18:10:26Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.9.0:copy-dependencies (copy-deps) on project test: Coud not build project for org.apache.kafka:kafka-clients:jar:4.2.0: Error resolving project artifact: The following artifacts could not be resolved: org.apache.kafka:kafka-clients:pom:4.2.0 (present, but unavailable): Could not find artifact org.apache.kafka:kafka-clients:pom:4.2.0 in central (https://repo.maven.apache.org/maven2) for project org.apache.kafka:kafka-clients:jar:4.2.0 -> [Help 1]

This change propagates the remote repositories from the project to the ProjectBuildingRequest used build the project for the parent artefacts. The approach was inspired by https://github.com/apache/maven-javadoc-plugin/blob/ace4fe073378474b53296bd8c7a3f4a3faa44e17/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java#L2364

I don't know the Maven API well, so I'm hoping someone can give me a thumbs up that the approach is generally in the right direction. I'll then spend time adding test case(s).

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@k-wall k-wall marked this pull request as draft February 4, 2026 14:00
@k-wall
Copy link
Copy Markdown
Contributor Author

k-wall commented Feb 10, 2026

Anyone?

@k-wall
Copy link
Copy Markdown
Contributor Author

k-wall commented Apr 28, 2026

I would really like to see this issue resolved, would any commiter be able to comment please?

ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProcessPlugins(false);
if (getProject().getRemoteArtifactRepositories() != null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getProject().getRemoteArtifactRepositories() it should be never null

@slawekjaranowski slawekjaranowski added the bug Something isn't working label May 12, 2026
Signed-off-by: Keith Wall <kwall@apache.org>
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProcessPlugins(false);
if (getProject().getRemoteArtifactRepositories() != null
&& !getProject().getRemoteArtifactRepositories().isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also getProject().getRemoteArtifactRepositories() should never be empty

@slawekjaranowski
Copy link
Copy Markdown
Member

@k-wall thanks, I have rebased with current muster to trigger CI build

@slawekjaranowski slawekjaranowski self-assigned this May 12, 2026
@slawekjaranowski slawekjaranowski marked this pull request as ready for review May 16, 2026 09:59
@slawekjaranowski slawekjaranowski added this to the 3.11.0 milestone May 16, 2026
Copy link
Copy Markdown
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

Can there be an IT or unit test for this?

@k-wall
Copy link
Copy Markdown
Contributor Author

k-wall commented May 19, 2026

Great, thanks for picking up. I'll see if I can add a test.

@slawekjaranowski
Copy link
Copy Markdown
Member

@k-wall thanks, I have rebased with current muster to trigger CI build

You can look at my coments

k-wall added 2 commits May 20, 2026 12:37
Add integration test to verify that when using copy-dependencies with
addParentPoms=true, the plugin correctly propagates the project's remote
repositories to the ProjectBuildingRequest when resolving parent POMs.

The test uses the "fake-remote-repository" pattern to ensure the custom
repository is NOT mirrored by MRM (Mock Repository Manager). This is critical
because MRM is configured as a global mirror in src/it/mrm/settings.xml with:
  <mirrorOf>*,!fake-remote-repository</mirrorOf>

By using id "fake-remote-repository", the repository is:
- NOT mirrored by MRM
- NOT inherited in the session's repository configuration
- ONLY available if explicitly propagated via setRemoteRepositories()

This ensures the test actually validates the fix.

TEST VALIDATION:
- WITHOUT fix: Test FAILS with "Could not build project" error at
  buildProjectFromArtifact() because fake-remote-repository is not propagated
- WITH fix: Test PASSES, parent POM successfully resolved and copied

Test structure (following copy-from-remote-repository pattern):
- repo/: Local repository with test artifacts (test-parent, test-child)
- pom.xml: Declares fake-remote-repository and dependency on test-child
- setup.bsh: Cleans local cache to force fresh resolution
- verify.bsh: Validates parent POM was copied to output

Assisted-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Keith Wall <kwall@apache.org>
Remove unnecessary null and empty checks for getProject().getRemoteArtifactRepositories()
as the reviewer (slawekjaranowski) noted these should never be null or empty in Maven.

Signed-off-by: Keith Wall <kwall@apache.org>
@k-wall
Copy link
Copy Markdown
Contributor Author

k-wall commented May 20, 2026

I've added an IT and believe I have addressed the feedback. Please take another look.

@slawekjaranowski slawekjaranowski merged commit 70b5356 into apache:master May 20, 2026
17 checks passed
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.

[MDEP-592] Regression: -Dmdep.addParentPoms=true causes <repositories> to be ignored

3 participants