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

Maven incorrectly builds POM when you override Shade transformers in a child

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 3.3.9
    • Fix Version/s: None
    • Labels:
      None

      Description

      Consider the project: https://github.com/stevenschlansker/maven-configure-transformer-bug/

      Simple 2 module project. Parent defines some Shade plugin configuration, notably a ResourceTransformer with a mainClass declaration.

      Child then tries to add a PropertiesMergingResourceTransformer, but somehow the mainClass declaration from the parent gets merged into this other transformer, causing a build failure:

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (assemble-app) on project maven-configure-transformer-bug-child: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade for parameter mainClass: Cannot find 'mainClass' in class org.springframework.boot.maven.PropertiesMergingResourceTransformer -> [Help 1]

      The effective POM shows that something extremely unintuitive is going on with model merging:

            <plugin>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.4.3</version>
              <executions>
                <execution>
                  <id>assemble-app</id>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <transformers>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.handlers</resource>
                      </transformer>
                      <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                        <resource>META-INF/spring.factories</resource>
                        <mainClass>foo</mainClass>
                        <collectSections>true</collectSections>
                      </transformer>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.schemas</resource>
                      </transformer>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                    </transformers>
                  </configuration>
                </execution>
              </executions>
              <dependencies>
                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
                  <version>1.3.3.RELEASE</version>
                  <scope>compile</scope>
                </dependency>
              </dependencies>
              <configuration>
                <transformers>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                    <resource>META-INF/spring.handlers</resource>
                  </transformer>
                  <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                    <resource>META-INF/spring.factories</resource>
                    <mainClass>foo</mainClass>
                    <collectSections>true</collectSections>
                  </transformer>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                    <resource>META-INF/spring.schemas</resource>
                  </transformer>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                  <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                </transformers>
              </configuration>
            </plugin>
      

      It is possible to escape this by adding combine.self="override" to the <transformers> node. But I think the configuration ending up on the wrong transformer is a bug, and the fact that it causes duplicate configuration sections is also extremely confusing. And somewhere in the shuffle the original CollectingManifestResourceTransformer is lost entirely. (Note that it's not even on the plugin path, so referencing it should be an error!)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rfscholte Robert Scholte
                Reporter:
                stevenschlansker Steven Schlansker
              • Votes:
                1 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: