title: Gradle legacy multi module build: working around bad choices
body: <p>I have a legacy WebApp project composed of many legacy modules and a few new modules. I'm working on migrating the existing project to a Gradle based build <em>without</em> changing the folder structure (at least for now).</p>
  
  <p>The module structure is very flat as in the following:</p>
  
  <pre><code>project-root
  |-- module1
  |-- module2
  |-- module3
  |-- module4
  |-- newModule (newly added!)
  |   |-- sub1
  |   |-- sub2
  </code></pre>
  
  <p>Now let's say <code>module1</code> and <code>module2</code> need to be deployed in a WAR file, say <code>war1.war</code>, <code>module3</code> and <code>module4</code> in a different WAR file, say <code>war2.war</code> and finally <code>newModule:sub1</code> and <code>newModule:sub2</code> will be deployed as two standalone applications.</p>
  
  <p>Now I'm debating about how to create these artifacts. Should I have a separate additional war module for each artifact, i.e., one for <code>war1</code> and the other for <code>war2</code>? Or should I have two tasks in the root project? If so, how can I use the war plugin to produce many different artifacts? Or should I just choose a module to be the host for the two artifacts, i.e., have <code>module1</code> build <code>war1</code> and <code>module3</code> build <code>war2</code> or something like that? Or finally should I reorganize the project (which I'm trying to avoid to do) to something like this:</p>
  
  <pre><code>project-root
  |-- war1
  |   |-- module1
  |   |-- module2
  |-- war2
  |   |-- module3
  |   |-- module4
  |-- newModule
  |   |-- sub1
  |   |-- sub2
  </code></pre>