You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Alexey Venderov (Jira)" <ji...@apache.org> on 2023/02/06 15:47:00 UTC
[jira] [Created] (MNG-7683) Plugins configuration is merged incorrectly
Alexey Venderov created MNG-7683:
------------------------------------
Summary: Plugins configuration is merged incorrectly
Key: MNG-7683
URL: https://issues.apache.org/jira/browse/MNG-7683
Project: Maven
Issue Type: Bug
Components: Inheritance and Interpolation
Affects Versions: 4.0.0-alpha-3, 4.0.x-candidate
Reporter: Alexey Venderov
Hi,
As was mentioned by my colleague [here|https://github.com/apache/maven/pull/866#discussion_r1058637665] there is a regression in the plugin configuration merging logic introduced in version {{4.0.0-alpha-3}}. The original assumption was that the issue is caused by [this|https://github.com/codehaus-plexus/plexus-utils/commit/67ac243dbc6434c03a9b1582d94aef6bf2b5cf95] change in the {{plexus-utils}} library. I wrote a small reproducer test: [https://github.com/c00ler/plexus-utils-merge-xml-reproducer/blob/main/src/test/java/com/github/avenderov/ReproducerTest.java] and run it with the {{plexus-utils}} versions before and after the change. Test passes with both versions. So it's not the change in the {{plexus-utils}}.
After that, I checked Maven sources and found out that {{Maven 4}} doesn't use {{Xpp3Dom}} and associated utilities from the {{plexus-utils}} anymore, and has its own merging logic implemented [here|https://github.com/apache/maven/blob/master/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java#L207]. The behavior of the configuration merging logic was correct (same as in maven 3.x) up until version {{4.0.0-alpha-2}} and then was changed in version {{4.0.0-alpha-3}}.
h3. Problem description.
We have the following {{foo-bar-plugin}} configuration in the parent pom:
{code:xml}
<pluginManagement>
<plugins>
<plugin>
<groupId>foo.bar</groupId>
<artifactId>foo-bar-plugin</artifactId>
<configuration>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<bar>
<value>foo</value>
</bar>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<foo>
<properties>
<property>
<name>prop1</name>
<value>value1</value>
</property>
</properties>
</foo>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
{code}
In the child pom, we want to make changes to the {{foo-bar-plugin}} configuration:
{code:xml}
<pluginManagement>
<plugins>
<plugin>
<groupId>foo.bar</groupId>
<artifactId>foo-bar-plugin</artifactId>
<configuration>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<foo>
<properties combine.children="append">
<property>
<name>prop2</name>
<value>value2</value>
</property>
</properties>
</foo>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
{code}
The expected effective pom after merging:
{code:xml}
<pluginManagement>
<plugins>
<plugin>
<groupId>foo.bar</groupId>
<artifactId>foo-bar-plugin</artifactId>
<configuration>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<bar>
<value>foo</value>
</bar>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<foo>
<properties combine.children="append">
<property>
<name>prop1</name>
<value>value1</value>
</property>
<property>
<name>prop2</name>
<value>value2</value>
</property>
</properties>
</foo>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
{code}
Instead {{Maven 4.0.0-alpha-3}} produces the following result:
{code:xml}
<pluginManagement>
<plugins>
<plugin>
<groupId>foo.bar</groupId>
<artifactId>foo-bar-plugin</artifactId>
<configuration>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<foo>
<properties>
<property>
<name>prop1</name>
<value>value1</value>
</property>
</properties>
</foo>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<foo>
<properties combine.children="append">
<property>
<name>prop2</name>
<value>value2</value>
</property>
</properties>
</foo>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
{code}
h3. Steps to reproduce.
We have a repository with the reproducer: [https://github.com/c00ler/maven-merge-xml-reproducer]:
* the [main|https://github.com/c00ler/maven-merge-xml-reproducer] branch produces a diff between {{maven 3.8.7}} and {{maven 4.0.0-alpha-3}}. It shows the described example;
* the [alpha2-alpha3|https://github.com/c00ler/maven-merge-xml-reproducer/tree/alpha2-alpha3] branch produces a diff between {{maven 4.0.0-alpha-2}} and {{maven 4.0.0-alpha-3}} that shows the change in the behavior;
After diving a little bit deeper I found out that the problem is actually caused by the fact that we have two nested plugins configurations, {{maven-compiler-plugin}} and {{maven-surefire-plugin}}, that need to be merged and it causes the problem. As can be seen from the example the configuration from the {{maven-surefire-plugin}} is getting merged to the {{maven-compiler-plugin}} and overrides its configuration. In the branch [single-plugin-merge|https://github.com/c00ler/maven-merge-xml-reproducer/tree/single-plugin-merge] I've left only {{maven-surefire-plugin}} and then the configuration is correctly merged even in {{maven 4.0.0-alpha-3}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)