gnodet-bot commented on code in PR #13492:
URL: https://github.com/apache/maven/pull/13492#discussion_r4267020834
##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInheritanceAssemblerTest.java:
##########
@@ -55,6 +61,48 @@ private Model getModel(String name) throws Exception {
return
xmlFactory.read(XmlReaderRequest.builder().path(getPom(name)).build());
}
+ /**
+ * An inherited plugin must still report the POM that declares it, as the
location of the plugin element
+ * itself is what tools use to resolve paths in the plugin configuration
against the declaring POM.
+ */
+ @Test
+ void testInheritedPluginKeepsItsLocation() throws Exception {
+ Model parent = readWithLocations(
+
"<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>parent</artifactId>"
+ +
"<version>1</version><packaging>pom</packaging><build><plugins><plugin>"
+ +
"<artifactId>some-plugin</artifactId></plugin></plugins></build>"
+ +
"<reporting><plugins><plugin><artifactId>some-report</artifactId></plugin></plugins>"
+ + "</reporting></project>",
+ "parent.xml");
+ Model child = readWithLocations(
+
"<project><modelVersion>4.0.0</modelVersion><parent><groupId>g</groupId>"
+ +
"<artifactId>parent</artifactId><version>1</version></parent>"
+ + "<artifactId>child</artifactId></project>",
+ "child.xml");
+
+ Model assembled = assembler.assembleModelInheritance(child, parent,
null, null);
+
+ Plugin plugin = assembled.getBuild().getPlugins().get(0);
+ InputLocation location = plugin.getLocation("");
+ assertNotNull(location);
+ assertEquals(parent.getBuild().getPlugins().get(0).getLocation(""),
location);
+ assertEquals("g:parent:1", location.getSource().getModelId());
+
+ ReportPlugin reportPlugin =
assembled.getReporting().getPlugins().get(0);
+ location = reportPlugin.getLocation("");
+ assertNotNull(location);
+
assertEquals(parent.getReporting().getPlugins().get(0).getLocation(""),
location);
+ assertEquals("g:parent:1", location.getSource().getModelId());
+ }
Review Comment:
💡 **Suggestion:** The existing test covers pure inheritance (child has no
plugin). Consider adding a companion test for the child-overrides-parent case —
where the child also declares the same plugin (with extra config), and we
confirm the child's own location is preserved (not overwritten by the parent's):
```java
@Test
void testChildPluginKeepsItsOwnLocation() throws Exception {
Model parent = readWithLocations(
"<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId>"
+ "<artifactId>parent</artifactId><version>1</version>"
+ "<packaging>pom</packaging><build><plugins><plugin>"
+
"<artifactId>some-plugin</artifactId></plugin></plugins></build>"
+ "</project>",
"parent.xml");
Model child = readWithLocations(
"<project><modelVersion>4.0.0</modelVersion><parent><groupId>g</groupId>"
+
"<artifactId>parent</artifactId><version>1</version></parent>"
+
"<artifactId>child</artifactId><build><plugins><plugin>"
+
"<artifactId>some-plugin</artifactId><version>1.0</version>"
+ "</plugin></plugins></build></project>",
"child.xml");
Model assembled = assembler.assembleModelInheritance(child, parent,
null, null);
Plugin plugin = assembled.getBuild().getPlugins().get(0);
InputLocation location = plugin.getLocation("");
assertNotNull(location);
assertEquals("child.xml", location.getSource().getLocation());
}
```
This guards the `tgt` loop path in `mergePluginContainer_Plugins`, where a
child re-declares the same plugin — ensuring `mergePlugin()` does not
accidentally lose the child's own `InputLocation`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]