title: How to inherit from a multimodule Maven project with all its goodies?
body: <p>The problem to which I cannot find a nice, scalable solution:</p>
  
  <p>I have a project that delivers multiple flavours of the given artifact. This has been set up as a multimodule project, currently with 3 modules:</p>
  
  <ul>
  <li>/flavour1_module</li>
  <li>/flavour2_module</li>
  <li>/flavour3_module</li>
  </ul>
  
  <p>The thing is that I have another 50 projects that need to be setup in the same way, i.e. delivering the 3 flavours.</p>
  
  <p>Solutions considered:</p>
  
  <ol>
  <li>turning the already created multimodule project into a parent for all other 50 projects
  <ul>
  <li><strong>Cons:</strong> It just doesn't work. The instructions kept withing parent's modules are not inherited, thus they are not executed.</li>
  </ul></li>
  <li>using <a href="http://maven.apache.org/archetype/maven-archetype-plugin/" rel="nofollow">maven-archetype-plugin</a> to create <a href="http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-multi-module-project.html" rel="nofollow">a multi-module project
  template</a>, and then creating all 50 projects based on the template
  <ul>
  <li><strong>Cons:</strong> if I would need flavour4, I need to manually update all 50 projects to add flavour4_module (and duplicate its content). Not scalable.</li>
  </ul></li>
  <li>embedding the configuration of all flavours into a single pom and enable or disable them based on profiles (i.e. using composition by profiles instead of inheritance via modules). Then pointing the 50 projects to it, as their parent. This would create "inline" modules
  <ul>
  <li><strong>Cons:</strong> I would need to implement on my own mechanisms which are provided by modules out of the box. (e.g. building every flavour in a separate directory). I would also lose the clear seperation that modules provide.</li>
  </ul></li>
  </ol>
  
  <p>Any ideas how to do it nicely? Is there any other option?</p>
  
  <p>Thanks,
  Lukasz</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Another option would be extending the <a href="http://maven.apache.org/plugins/maven-reactor-plugin/index.html" rel="nofollow">maven-reactor-plugin</a> with <em>reactor:inject-modules</em> goal, which would download module definition from an external artifact, and attach its definition as a normal module. This would create a new module on the fly. Then all 50 projects could make this pom.xml their parent.</p>
  
  <p>The configuration would look like this (a draft):</p>
  
  <pre><code>&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-reactor-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;id&gt;inject&lt;/id&gt;
        &lt;phase&gt;initialize&lt;/phase&gt;
        &lt;goals&gt;
          &lt;goal&gt;inject-modules&lt;/goal&gt;
        &lt;/goals&gt;
        &lt;configuration&gt;
          &lt;modules&gt;
            &lt;module&gt;
              &lt;artifactId&gt;flavour1_module&lt;/artifactId&gt;
              &lt;groupId&gt;[ groupId ]&lt;/groupId&gt;
              &lt;version&gt;[ version ]&lt;/version&gt;
            &lt;/module&gt;
            &lt;module&gt;
              &lt;artifactId&gt;flavour2_module&lt;/artifactId&gt;
              &lt;groupId&gt;[ groupId ]&lt;/groupId&gt;
              &lt;version&gt;[ version ]&lt;/version&gt;
            &lt;/module&gt;
            &lt;module&gt;
              &lt;artifactId&gt;flavour3_module&lt;/artifactId&gt;
              &lt;groupId&gt;[ groupId ]&lt;/groupId&gt;
              &lt;version&gt;[ version ]&lt;/version&gt;
            &lt;/module&gt;
          &lt;/modules&gt;
        &lt;/configuration&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>Would going this way make sense?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Writing a plugin that manipulates the list of modules to execute (the idea of module injection that I described above) doesn't seem to be possible to implement, because modules are processed by maven core, and the mechanism was not designed to be extended with a plugin. This is confirmed by the fact that both plugins that do a similar job i.e.  manipulating the list of projects to execute:</p>
  
  <ul>
  <li><a href="http://maven.apache.org/plugins/maven-reactor-plugin/index.html" rel="nofollow">maven-reactor-plugin</a></li>
  <li><a href="http://maven.apache.org/plugins/maven-invoker-plugin/" rel="nofollow">maven-invoker-plugin</a></li>
  </ul>
  
  <p>do the trick by executing a system call to create maven child process. For me it is not the way to go, because it's a very unstable solution. Indeed <a href="http://maven.apache.org/plugins/maven-reactor-plugin/index.html" rel="nofollow">maven-reactor-plugin</a> became <a href="https://cwiki.apache.org/MAVEN/maven-3x-plugin-compatibility-matrix.html" rel="nofollow">incompatible</a> with Maven3.</p>
  
  <p><a href="http://maven.apache.org/plugins/maven-invoker-plugin/" rel="nofollow">maven-invoker-plugin</a> still looks promising. The plugin was originally designed to run integration tests, but it would be possible to use it to extend e.g. the compilation phase.
  But it requires the child pom.xml-s to be treated as resources and modified on the fly. For the problem that I described here the solution would be too complicated and unstable. I would prefer something lighter that could operate in memory while building maven model.</p>
  
  <p>So for now I use profiles, trying to make them as compact as possible. Probably in a while I will need again to think about the problem.</p>