Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7683

Plugin configuration is merged incorrectly

    XMLWordPrintableJSON

Details

    Description

      Hi,

      As was mentioned by my colleague here 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 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. 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.

      Problem description.

      We have the following foo-bar-plugin configuration in the parent pom:

      <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>
      

      In the child pom, we want to make changes to the foo-bar-plugin configuration:

      <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>
      

      The expected effective pom after merging (maven-compiler-plugin configuration is persisted, maven-surefire-plugin configuration is merged):

      <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>
      

      Instead Maven 4.0.0-alpha-3 produces the following result:

      <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>
      

      Steps to reproduce.

      We have a repository with the reproducer: https://github.com/c00ler/maven-merge-xml-reproducer:

      • the main branch produces a diff between maven 3.8.7 and maven 4.0.0-alpha-3. It shows the described example;
      • the 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 I've left only maven-surefire-plugin and then the configuration is correctly merged even in maven 4.0.0-alpha-3.

      Attachments

        Issue Links

          Activity

            People

              gnodet Guillaume Nodet
              avenderov Alexey Venderov
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: