gnodet commented on PR #1209:
URL: https://github.com/apache/maven/pull/1209#issuecomment-2839880777
> > > One challenge we have with Maven Tiles is that plugin configurations
for the same plugin will overwrite each other. How is this handled with mixins?
> >
> >
> > They use the same mechanism as parents, so it will be like if one plugin
definition is in the parent and the other one in the grand-parent. They end up
being merged. The order will have to be clearly specified though.
>
> When you say merged - in what way?
>
> A (parent):
>
> ```
> <build>
> <plugins>
> <plugin>
> <groupId>plugin</groupId>
> <artifactId>plugin</artifactId>
> <configuration>
> <a>a</a>
> <c>a</c>
> </configuration>
> </plugin>
> </plugins>
> </build>
> ```
>
> B (child)
>
> ```
> <build>
> <plugins>
> <plugin>
> <groupId>plugin</groupId>
> <artifactId>plugin</artifactId>
> <configuration>
> <b>b</b>
> <c>b</c>
> </configuration>
> </plugin>
> </plugins>
> </build>
> ```
>
> What would be the outcome of the above?
>
> 1. The entire plugin is configured by A or B depending on order
> 2. Everything is merged but A has priority so
> a
> b
> a
> 3. Everything is merged but B has priority so
> a
> b
> b
> 4. other outcome
Maven identifies plugins by their groupId and artifactId. Since both parent
and child define the same plugin, their configurations are merged.
## Configuration Merging:
For non-conflicting elements (elements present in one POM but not the
other), Maven includes both elements in the final configuration.
For conflicting elements (elements with the same name in both parent and
child), the child's configuration takes precedence and overrides the parent's
configuration.
By default, Maven does not append or merge the content of elements unless
explicitly instructed (e.g., using combine.children="append").
## Non-conflicting elements:
Parent has <a>a</a>, which is not present in the child. This element is
included in the final configuration.
Child has <b>b</b>, which is not present in the parent. This element is
included in the final configuration.
## Conflicting elements:
Both parent and child define <c>. The parent has <c>a</c>, and the child has
<c>b</c>.
The child's <c>b</c> overrides the parent's <c>a</c>.
## Resulting Configuration:
The merged configuration for the plugin in the child project will include:
```
<a>a</a> (from parent, non-conflicting).
<b>b</b> (from child, non-conflicting).
<c>b</c> (from child, overriding parent's <c>a</c>).
```
Final Outcome
The effective configuration for the plugin in the child project (B) will be:
```xml
<build>
<plugins>
<plugin>
<groupId>plugin</groupId>
<artifactId>plugin</artifactId>
<configuration>
<a>a</a>
<b>b</b>
<c>b</c>
</configuration>
</plugin>
</plugins>
</build>
```
## Notes
If you want to append configurations (e.g., combine `<c>` values from parent
and child), you can use the `combine.children="append"` attribute in the child
POM. For example:
```xml
<configuration combine.children="append">
<b>b</b>
<c>b</c>
</configuration>
```
This would require a more complex structure for `<c>` (e.g., as a list),
which depends on the plugin’s configuration schema.
If you want to prevent inheritance of the parent’s configuration, you can
add `<inherited>false</inherited>` to the child’s plugin definition:
```xml
<plugin>
<groupId>plugin</groupId>
<artifactId>plugin</artifactId>
<inherited>false</inherited>
<configuration>
<b>b</b>
<c>b</c>
</configuration>
</plugin>
```
This would result in only `<b>b</b>` and `<c>b</c>` in the child’s
configuration, ignoring `<a>a</a>` and `<c>a</c>` from the parent.
--
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]