You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Robert Scholte (JIRA)" <ji...@apache.org> on 2017/06/19 17:32:00 UTC

[jira] [Closed] (MNG-6016) Maven incorrectly builds POM when you override Shade transformers in a child

     [ https://issues.apache.org/jira/browse/MNG-6016?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Scholte closed MNG-6016.
-------------------------------
    Resolution: Not A Problem
      Assignee: Robert Scholte

The issue here is that the configuration-content is just a bunch of xml tags. When Maven tries to merge because of inheritence it is a per-element comparison; it is not aware of lists or maps.
So what's happening here is that the second transformer of the parent is merged with the second of the child.
With Lists you can simply add the magic attribute {{combine.children="append"}} to the transformers-element, which means that the transformer-elements won't be merged but appended.
Since Maven 3.3.9 it is also possible to specify {{combine.id}}, which is useful in case of Maps. Transformers having the same combine.id in parent and child will be merged, the rest will be appended.
Also read http://blog.sonatype.com/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/ for more details.

> Maven incorrectly builds POM when you override Shade transformers in a child
> ----------------------------------------------------------------------------
>
>                 Key: MNG-6016
>                 URL: https://issues.apache.org/jira/browse/MNG-6016
>             Project: Maven
>          Issue Type: Bug
>          Components: Inheritance and Interpolation, POM
>    Affects Versions: 3.3.9
>            Reporter: Steven Schlansker
>            Assignee: Robert Scholte
>
> 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:
> {quote}
> [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]
> {quote}
> The effective POM shows that something extremely unintuitive is going on with model merging:
> {code}
>       <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>
> {code}
> 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!)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)