#### Merging feature groups

There could be a situation when the same feature group is brought into the config as a dependency of a few other feature groups. Which means its basic feature set is included into the final configuration multiple times but, taking into account possible customizations, each time it might be slightly different.

IMPORTANT: In that case the feature configurations will be merged. The features that are included later in the config will overwrite the common parameters of the corresponding features included earlier. But they will not completely replace the feature configurations that were added earlier.

For example, suppose we have these feature specs:
[source,xml]
----
 <feature-spec xmlns="urn:jboss:galleon:feature-spec:1.0" name="featureA">
   <params>
     <param name="name" feature-id="true"/>
     <param name="p1" default="feature-spec"/>
     <param name="p2" default="feature-spec"/>
     <param name="p3" default="feature-spec"/>
   </params>
 </feature-spec>
----

[source,xml]
----
 <feature-spec xmlns="urn:jboss:galleon:feature-spec:1.0" name="featureB">
   <params>
     <param name="name" feature-id="true"/>
     <param name="p1" default="feature-spec"/>
     <param name="p2" default="feature-spec"/>
     <param name="p3" default="feature-spec"/>
   </params>
 </feature-spec>
----

and these feature groups
[source,xml]
----
<feature-group-spec name="group1" xmlns="urn:jboss:galleon:feature-group:1.0">

  <feature spec="featureA">
    <param name="name" value="a1"/>
    <param name="p1" value="group1"/>
    <param name="p2" value="group1"/>
    <param name="p3" value="group1"/>
  </feature>
  <feature spec="featureA">
    <param name="name" value="a2"/>
  </feature>
  <feature spec="featureA">
    <param name="name" value="a3"/>
  </feature>
  <feature spec="featureB">
    <param name="name" value="b1"/>
    <param name="p1" value="gorup1"/>
    <param name="p2" value="group1"/>
    <param name="p3" value="group1"/>
  </feature>
  <feature spec="featureB">
    <param name="name" value="b2"/>
  </feature>

</feature-group-spec>
----

[source,xml]
----
<feature-group-spec name="group2" xmlns="urn:jboss:galleon:feature-group:1.0">

  <feature-group name="group1">
    <include feature-id="featureA:name="a1">
      <param name="p1" value="group2"/>
      <param name="p2" value="group2"/>
    </feature>
    <exclude feature-id="featureA:name=a3"/>
    <include feature-id="featureB:name="b1">
      <param name="p2" value="group2"/>
    </feature>
    <exclude feature-id="featureB:name=b2"/>
  </feature-group>

</feature-group-spec>
----

[source,xml]
----
<feature-group-spec name="group3" xmlns="urn:jboss:galleon:feature-group:1.0">

  <feature-group name="group1">
    <include feature-id="featureA:name="a1">
      <param name="p1" value="group3"/>
    </feature>
    <exclude feature-id="featureA:name=a2"/>
    <include feature-id="featureB:name="b1">
      <param name="p3" value="group3"/>
    </feature>
    <exclude feature-id="featureB:name=b2"/>
  </feature-group>

</feature-group-spec>
----

Now this configuration
[source,xml]
----
<config name="main">
  <feature-group name="group2"/>
  <feature-group name="group3"/>
</config>
----

will contain
[%header,options="autowidth"]
|===
|Feature spec |name |p1 |p2 |p3
|featureA |a1 |group3 |group2 |group1
|featureA |a2 |feature-spec |feature-spec |feature-spec
|featureA |a3 |feature-spec |feature-spec |feature-spec
|featureB |b1 |group1 |group2 |group3
|===

