elharo commented on issue #471:
URL: 
https://github.com/apache/maven-ear-plugin/issues/471#issuecomment-5103950494

   This is almost certainly a **user error** stemming from a misunderstanding 
of how Maven merges XML configurations between a base POM and a profile, rather 
than a bug in the `maven-ear-plugin`.
   
   Here is the technical breakdown of what is actually happening:
   
   **The Mechanism of the "Bug"**
   The user reports that when they activate a profile to add an extra 
`webModule` configuration, all the other `webModule` configurations defined in 
the base POM lose their custom `bundleFileName` settings and revert to default 
names.
   
   In Maven, when you define a list-based configuration (like `<modules>`) in 
the base `<build>` section and then define the same list in a `<profile>`, 
Maven's default behavior is to **overwrite** the base list with the profile's 
list.
   
   1. **Before the profile:** The plugin reads the base POM, sees explicit 
`<webModule>` configurations for modules A and B (including their custom 
`bundleFileName` properties), and applies them.
   2. **With the profile activated:** Maven replaces the entire base 
`<modules>` list with the one from the profile. Now, only the "extra" module C 
is explicitly configured.
   3. **The Ear Plugin's Default Behavior:** Even though modules A and B are no 
longer explicitly configured in the plugin's `<modules>` section, they are 
still listed in the project's `<dependencies>`. The `maven-ear-plugin` 
automatically packages any relevant dependencies it finds. Because it no longer 
has explicit configuration for A and B, it packages them using the default 
standard naming conventions, making the user think the `bundleFileName` was 
"reset."
   
   **The Solution (Why it's not a plugin bug)**
   This is core Maven architecture, not something the plugin controls. To fix 
this, the user needs to instruct Maven to *append* the profile's module list to 
the base list, rather than overwrite it.
   
   They can do this using the `combine.children="append"` attribute in their 
profile configuration:
   
   ```xml
   <profile>
     <id>add-extra-war</id>
     <build>
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-ear-plugin</artifactId>
           <configuration>
             <!-- This attribute tells Maven to merge, not overwrite -->
             <modules combine.children="append"> 
               <webModule>
                 <groupId>com.example</groupId>
                 <artifactId>extra-war</artifactId>
                 <bundleFileName>extra.war</bundleFileName>
               </webModule>
             </modules>
           </configuration>
         </plugin>
       </plugins>
     </build>
   </profile>
   
   ```
   
   Because the issue arises from standard Maven inheritance rules and can be 
solved using standard Maven XML attributes, this should be categorized as user 
error and closed as invalid.


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

Reply via email to