Skip to content

Commit 70b5356

Browse files
authored
fix: fix addParentPoms=true causes repositories to be ignored. (#1585)
* fix: fix addParentPoms=true causes repositories to be ignored. Signed-off-by: Keith Wall <kwall@apache.org> * 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 <noreply@anthropic.com> Signed-off-by: Keith Wall <kwall@apache.org> * 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 <kwall@apache.org> --------- Signed-off-by: Keith Wall <kwall@apache.org>
1 parent 51d8939 commit 70b5356

8 files changed

Lines changed: 282 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = clean package
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Licensed to the Apache Software Foundation (ASF) under one
5+
~ or more contributor license agreements. See the NOTICE file
6+
~ distributed with this work for additional information
7+
~ regarding copyright ownership. The ASF licenses this file
8+
~ to you under the Apache License, Version 2.0 (the
9+
~ "License"); you may not use this file except in compliance
10+
~ with the License. You may obtain a copy of the License at
11+
~
12+
~ http://www.apache.org/licenses/LICENSE-2.0
13+
~
14+
~ Unless required by applicable law or agreed to in writing,
15+
~ software distributed under the License is distributed on an
16+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
~ KIND, either express or implied. See the License for the
18+
~ specific language governing permissions and limitations
19+
~ under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<groupId>org.apache.maven.its.dependency</groupId>
29+
<artifactId>test</artifactId>
30+
<version>1.0-SNAPSHOT</version>
31+
32+
<name>Test MDEP-592</name>
33+
<description>
34+
Test for MDEP-592: addParentPoms=true causes repositories to be ignored.
35+
36+
This test verifies that when using copy-dependencies with addParentPoms=true,
37+
the plugin correctly uses the project's configured remote repositories to resolve
38+
parent POMs. The test dependency (test-child) has a parent POM (test-parent) that
39+
is only available in a custom repository (fake-remote-repository, not Maven Central).
40+
41+
CRITICAL: This test uses repository id "fake-remote-repository" which is explicitly
42+
excluded from MRM mirroring in src/it/mrm/settings.xml. This ensures the repository
43+
is ONLY available if properly propagated via setRemoteRepositories().
44+
45+
Without the fix, the parent POM resolution would fail because the custom repository
46+
would not be propagated to the ProjectBuildingRequest.
47+
</description>
48+
49+
<properties>
50+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
51+
</properties>
52+
53+
<repositories>
54+
<repository>
55+
<id>fake-remote-repository</id>
56+
<url>file:///${basedir}/repo/</url>
57+
<releases>
58+
<checksumPolicy>ignore</checksumPolicy>
59+
</releases>
60+
</repository>
61+
</repositories>
62+
63+
<dependencies>
64+
<dependency>
65+
<groupId>org.apache.maven.its.mdep592</groupId>
66+
<artifactId>test-child</artifactId>
67+
<version>1.0</version>
68+
</dependency>
69+
</dependencies>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<artifactId>maven-dependency-plugin</artifactId>
75+
<version>@project.version@</version>
76+
<executions>
77+
<execution>
78+
<id>test-addparentpoms</id>
79+
<goals>
80+
<goal>copy-dependencies</goal>
81+
</goals>
82+
<phase>package</phase>
83+
<configuration>
84+
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
85+
<useRepositoryLayout>true</useRepositoryLayout>
86+
<copyPom>true</copyPom>
87+
<addParentPoms>true</addParentPoms>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
95+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Licensed to the Apache Software Foundation (ASF) under one
5+
~ or more contributor license agreements. See the NOTICE file
6+
~ distributed with this work for additional information
7+
~ regarding copyright ownership. The ASF licenses this file
8+
~ to you under the Apache License, Version 2.0 (the
9+
~ "License"); you may not use this file except in compliance
10+
~ with the License. You may obtain a copy of the License at
11+
~
12+
~ http://www.apache.org/licenses/LICENSE-2.0
13+
~
14+
~ Unless required by applicable law or agreed to in writing,
15+
~ software distributed under the License is distributed on an
16+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
~ KIND, either express or implied. See the License for the
18+
~ specific language governing permissions and limitations
19+
~ under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<parent>
29+
<groupId>org.apache.maven.its.mdep592</groupId>
30+
<artifactId>test-parent</artifactId>
31+
<version>1.0</version>
32+
</parent>
33+
34+
<artifactId>test-child</artifactId>
35+
36+
<name>Test Child for MDEP-592</name>
37+
<description>
38+
Child artifact for testing MDEP-592. This artifact has a parent POM that is only
39+
available in a custom repository. The test verifies that addParentPoms=true correctly
40+
uses the configured repository to resolve the parent.
41+
</description>
42+
43+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Licensed to the Apache Software Foundation (ASF) under one
5+
~ or more contributor license agreements. See the NOTICE file
6+
~ distributed with this work for additional information
7+
~ regarding copyright ownership. The ASF licenses this file
8+
~ to you under the Apache License, Version 2.0 (the
9+
~ "License"); you may not use this file except in compliance
10+
~ with the License. You may obtain a copy of the License at
11+
~
12+
~ http://www.apache.org/licenses/LICENSE-2.0
13+
~
14+
~ Unless required by applicable law or agreed to in writing,
15+
~ software distributed under the License is distributed on an
16+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
~ KIND, either express or implied. See the License for the
18+
~ specific language governing permissions and limitations
19+
~ under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<groupId>org.apache.maven.its.mdep592</groupId>
29+
<artifactId>test-parent</artifactId>
30+
<version>1.0</version>
31+
<packaging>pom</packaging>
32+
33+
<name>Test Parent for MDEP-592</name>
34+
<description>
35+
Minimal parent POM for testing MDEP-592: addParentPoms=true causes repositories to be ignored.
36+
This parent POM is only available in a custom repository, not Maven Central.
37+
</description>
38+
39+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
import org.codehaus.plexus.util.*;
22+
23+
// Clean up test artifacts from local repository to ensure fresh test
24+
// This forces Maven to download artifacts from the fake-remote-repository
25+
// rather than using cached versions
26+
String[] foldersToDelete = {
27+
"org/apache/maven/its/mdep592/test-parent",
28+
"org/apache/maven/its/mdep592/test-child"
29+
};
30+
31+
try
32+
{
33+
for ( String folderToDelete : foldersToDelete )
34+
{
35+
FileUtils.deleteDirectory( new File( localRepositoryPath, folderToDelete ) );
36+
}
37+
}
38+
catch( IOException e )
39+
{
40+
e.printStackTrace();
41+
return false;
42+
}
43+
44+
return true;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
22+
File outputDir = new File( basedir, "target/dependencies" );
23+
24+
String[] expectedFiles = {
25+
"org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.jar",
26+
"org/apache/maven/its/mdep592/test-child/1.0/test-child-1.0.pom",
27+
// CRITICAL TEST for MDEP-592: Parent POM from custom repository
28+
// Without the fix, this file would be missing because the custom repository
29+
// would not be propagated to the ProjectBuildingRequest
30+
"org/apache/maven/its/mdep592/test-parent/1.0/test-parent-1.0.pom"
31+
};
32+
33+
for ( String expectedFile : expectedFiles )
34+
{
35+
File file = new File( outputDir, expectedFile );
36+
if ( !file.isFile() )
37+
{
38+
throw new Exception( "Missing file " + file );
39+
}
40+
}
41+
42+
return true;

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ private MavenProject buildProjectFromArtifact(Artifact artifact) throws MojoExec
381381
ProjectBuildingRequest buildingRequest =
382382
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
383383
buildingRequest.setProcessPlugins(false);
384+
buildingRequest.setRemoteRepositories(getProject().getRemoteArtifactRepositories());
384385
return projectBuilder.build(artifact, buildingRequest).getProject();
385386
} catch (ProjectBuildingException e) {
386387
throw new MojoExecutionException("Could not build project for " + artifact.getId(), e);

0 commit comments

Comments
 (0)