From 207358415e483a84d37f9c8f58759a8b0d8c6a19 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 4 Feb 2026 13:21:29 +0000 Subject: [PATCH 1/3] fix: fix addParentPoms=true causes repositories to be ignored. Signed-off-by: Keith Wall --- .../fromDependencies/AbstractDependencyFilterMojo.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java index b14f0113d..8e3a0f531 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java @@ -381,9 +381,13 @@ private MavenProject buildProjectFromArtifact(Artifact artifact) throws MojoExec ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); buildingRequest.setProcessPlugins(false); + if (getProject().getRemoteArtifactRepositories() != null + && !getProject().getRemoteArtifactRepositories().isEmpty()) { + buildingRequest.setRemoteRepositories(getProject().getRemoteArtifactRepositories()); + } return projectBuilder.build(artifact, buildingRequest).getProject(); } catch (ProjectBuildingException e) { - throw new MojoExecutionException("Coud not build project for " + artifact.getId(), e); + throw new MojoExecutionException("Could not build project for " + artifact.getId(), e); } } From 64bd4168345ac2db53bd204bcf7dc55d935df72c Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 20 May 2026 11:43:26 +0100 Subject: [PATCH 2/3] test: add integration test for MDEP-592 addParentPoms repository fix 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: *,!fake-remote-repository 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 Signed-off-by: Keith Wall --- .../invoker.properties | 18 ++++ .../pom.xml | 95 ++++++++++++++++++ .../mdep592/test-child/1.0/test-child-1.0.jar | Bin 0 -> 318 bytes .../mdep592/test-child/1.0/test-child-1.0.pom | 43 ++++++++ .../test-parent/1.0/test-parent-1.0.pom | 39 +++++++ .../setup.bsh | 44 ++++++++ .../verify.bsh | 42 ++++++++ 7 files changed, 281 insertions(+) create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/invoker.properties create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/pom.xml create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/setup.bsh create mode 100644 src/it/projects/mdep-592-addparentpoms-custom-repo/verify.bsh diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/invoker.properties b/src/it/projects/mdep-592-addparentpoms-custom-repo/invoker.properties new file mode 100644 index 000000000..a644cb7ee --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = clean package diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/pom.xml b/src/it/projects/mdep-592-addparentpoms-custom-repo/pom.xml new file mode 100644 index 000000000..1ec6ecf30 --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/pom.xml @@ -0,0 +1,95 @@ + + + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test MDEP-592 + + Test for MDEP-592: addParentPoms=true causes repositories to be ignored. + + This test verifies that when using copy-dependencies with addParentPoms=true, + the plugin correctly uses the project's configured remote repositories to resolve + parent POMs. The test dependency (test-child) has a parent POM (test-parent) that + is only available in a custom repository (fake-remote-repository, not Maven Central). + + CRITICAL: This test uses repository id "fake-remote-repository" which is explicitly + excluded from MRM mirroring in src/it/mrm/settings.xml. This ensures the repository + is ONLY available if properly propagated via setRemoteRepositories(). + + Without the fix, the parent POM resolution would fail because the custom repository + would not be propagated to the ProjectBuildingRequest. + + + + UTF-8 + + + + + fake-remote-repository + file:///${basedir}/repo/ + + ignore + + + + + + + org.apache.maven.its.mdep592 + test-child + 1.0 + + + + + + + maven-dependency-plugin + @project.version@ + + + test-addparentpoms + + copy-dependencies + + package + + ${project.build.directory}/dependencies + true + true + true + + + + + + + + diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..fb6dc6a70324f5245d70932421f44c572076eed5 GIT binary patch literal 318 zcmWIWW@h1HVBlb2D2dt*(j{<{BKL=j-;__snS@Z(Y5MyxzK6=gyqp9At3C_`%a6JuhD!Pv48BtF{Cg7=>IY z@I7}@N5e0)z~`jC#z~#CSD!q6^ppu`A3H~GYTs8opy@V19N^8!#KnNyu}E%5b`Qkq lj7%a72*)EE3vxUHXakwpyb|Ee$_7%!1cbFfdNqi{004l`L(%{M literal 0 HcmV?d00001 diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom new file mode 100644 index 000000000..9fda05651 --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom @@ -0,0 +1,43 @@ + + + + + + + 4.0.0 + + + org.apache.maven.its.mdep592 + test-parent + 1.0 + + + test-child + + Test Child for MDEP-592 + + Child artifact for testing MDEP-592. This artifact has a parent POM that is only + available in a custom repository. The test verifies that addParentPoms=true correctly + uses the configured repository to resolve the parent. + + + diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom new file mode 100644 index 000000000..1a316bbaf --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom @@ -0,0 +1,39 @@ + + + + + + + 4.0.0 + + org.apache.maven.its.mdep592 + test-parent + 1.0 + pom + + Test Parent for MDEP-592 + + Minimal parent POM for testing MDEP-592: addParentPoms=true causes repositories to be ignored. + This parent POM is only available in a custom repository, not Maven Central. + + + diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/setup.bsh b/src/it/projects/mdep-592-addparentpoms-custom-repo/setup.bsh new file mode 100644 index 000000000..bffff2276 --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/setup.bsh @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.*; +import org.codehaus.plexus.util.*; + +// Clean up test artifacts from local repository to ensure fresh test +// This forces Maven to download artifacts from the fake-remote-repository +// rather than using cached versions +String[] foldersToDelete = { + "org/apache/maven/its/mdep592/test-parent", + "org/apache/maven/its/mdep592/test-child" +}; + +try +{ + for ( String folderToDelete : foldersToDelete ) + { + FileUtils.deleteDirectory( new File( localRepositoryPath, folderToDelete ) ); + } +} +catch( IOException e ) +{ + e.printStackTrace(); + return false; +} + +return true; diff --git a/src/it/projects/mdep-592-addparentpoms-custom-repo/verify.bsh b/src/it/projects/mdep-592-addparentpoms-custom-repo/verify.bsh new file mode 100644 index 000000000..207d759f1 --- /dev/null +++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/verify.bsh @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.*; + +File outputDir = new File( basedir, "target/dependencies" ); + +String[] expectedFiles = { + "org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar", + "org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom", + // CRITICAL TEST for MDEP-592: Parent POM from custom repository + // Without the fix, this file would be missing because the custom repository + // would not be propagated to the ProjectBuildingRequest + "org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom" +}; + +for ( String expectedFile : expectedFiles ) +{ + File file = new File( outputDir, expectedFile ); + if ( !file.isFile() ) + { + throw new Exception( "Missing file " + file ); + } +} + +return true; From 09b4b4a0ed39ee8b8facbd23bd874e5968db07d7 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 20 May 2026 13:45:55 +0100 Subject: [PATCH 3/3] fix: simplify MDEP-592 fix per reviewer feedback 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 --- .../fromDependencies/AbstractDependencyFilterMojo.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java index 8e3a0f531..de605f1aa 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java @@ -381,10 +381,7 @@ private MavenProject buildProjectFromArtifact(Artifact artifact) throws MojoExec ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); buildingRequest.setProcessPlugins(false); - if (getProject().getRemoteArtifactRepositories() != null - && !getProject().getRemoteArtifactRepositories().isEmpty()) { - buildingRequest.setRemoteRepositories(getProject().getRemoteArtifactRepositories()); - } + buildingRequest.setRemoteRepositories(getProject().getRemoteArtifactRepositories()); return projectBuilder.build(artifact, buildingRequest).getProject(); } catch (ProjectBuildingException e) { throw new MojoExecutionException("Could not build project for " + artifact.getId(), e);