This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 70b53569 fix: fix addParentPoms=true causes repositories to be 
ignored. (#1585)
70b53569 is described below

commit 70b535690ecbf985e795cabca9869d66a2c68e10
Author: Keith Wall <[email protected]>
AuthorDate: Wed May 20 23:17:21 2026 +0100

    fix: fix addParentPoms=true causes repositories to be ignored. (#1585)
    
    * fix: fix addParentPoms=true causes repositories to be ignored.
    
    Signed-off-by: Keith Wall <[email protected]>
    
    * 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:
      <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 <[email protected]>
    Signed-off-by: Keith Wall <[email protected]>
    
    * 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 <[email protected]>
    
    ---------
    
    Signed-off-by: Keith Wall <[email protected]>
---
 .../invoker.properties                             |  18 ++++
 .../mdep-592-addparentpoms-custom-repo/pom.xml     |  95 +++++++++++++++++++++
 .../its/mdep592/test-child/1.0/test-child-1.0.jar  | Bin 0 -> 318 bytes
 .../its/mdep592/test-child/1.0/test-child-1.0.pom  |  43 ++++++++++
 .../mdep592/test-parent/1.0/test-parent-1.0.pom    |  39 +++++++++
 .../mdep-592-addparentpoms-custom-repo/setup.bsh   |  44 ++++++++++
 .../mdep-592-addparentpoms-custom-repo/verify.bsh  |  42 +++++++++
 .../AbstractDependencyFilterMojo.java              |   1 +
 8 files changed, 282 insertions(+)

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 00000000..a644cb7e
--- /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 00000000..1ec6ecf3
--- /dev/null
+++ b/src/it/projects/mdep-592-addparentpoms-custom-repo/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>Test MDEP-592</name>
+  <description>
+    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.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <repositories>
+    <repository>
+      <id>fake-remote-repository</id>
+      <url>file:///${basedir}/repo/</url>
+      <releases>
+        <checksumPolicy>ignore</checksumPolicy>
+      </releases>
+    </repository>
+  </repositories>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.mdep592</groupId>
+      <artifactId>test-child</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>test-addparentpoms</id>
+            <goals>
+              <goal>copy-dependencies</goal>
+            </goals>
+            <phase>package</phase>
+            <configuration>
+              
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
+              <useRepositoryLayout>true</useRepositoryLayout>
+              <copyPom>true</copyPom>
+              <addParentPoms>true</addParentPoms>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
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 00000000..fb6dc6a7
Binary files /dev/null and 
b/src/it/projects/mdep-592-addparentpoms-custom-repo/repo/org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar
 differ
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 00000000..9fda0565
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.its.mdep592</groupId>
+    <artifactId>test-parent</artifactId>
+    <version>1.0</version>
+  </parent>
+
+  <artifactId>test-child</artifactId>
+
+  <name>Test Child for MDEP-592</name>
+  <description>
+    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.
+  </description>
+
+</project>
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 00000000..1a316bba
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mdep592</groupId>
+  <artifactId>test-parent</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <name>Test Parent for MDEP-592</name>
+  <description>
+    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.
+  </description>
+
+</project>
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 00000000..bffff227
--- /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 00000000..207d759f
--- /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;
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 c7e1a50b..de605f1a 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,6 +381,7 @@ public abstract class AbstractDependencyFilterMojo extends 
AbstractDependencyMoj
             ProjectBuildingRequest buildingRequest =
                     new 
DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
             buildingRequest.setProcessPlugins(false);
+            
buildingRequest.setRemoteRepositories(getProject().getRemoteArtifactRepositories());
             return projectBuilder.build(artifact, 
buildingRequest).getProject();
         } catch (ProjectBuildingException e) {
             throw new MojoExecutionException("Could not build project for " + 
artifact.getId(), e);

Reply via email to