title: gradle ear application packaging for multiple environment
body: <p>I have a web enterprise application that I am trying to automate building the EAR file for it with gradle (for the first time).</p>
  
  <p>I have 2 projects</p>
  
  <p>1 is the enterprise application APP_EAR and the other one is a dynamic web application APP that will be exported as a war file inside the main APP_EAR ear file.</p>
  
  <p>I figured out how to use gradle to generate a war file for the dynamic web app, I am not sure how to use gradle to create the ear file that contains this war file.</p>
  
  <p>The war file for my APP contains 3 tasks for each environment:</p>
  
  <p>sys (system testing), qa (quality control) and prod for production</p>
  
  <p>I created 3 tasks in the build.gradle for my APP like this:</p>
  
  <pre><code>task buildSys {
  dependsOn copySys, war
  }
  
  task buildQa {
  dependsOn copyQa, war
  }
  
  task buildProd {
  dependsOn copyProd, war
  }
  </code></pre>
  
  <p>the copySys, copyProd, etc... are just copy tasks that copies the appropriate configuration files for the environment I am targeting, before the war is created.  </p>
  
  <p>let's say I am creating a war file for sys , then I execute gradle buildSys </p>
  
  <p>What I am trying to do is the following:</p>
  
  <p>Assuming I want to create an EAR file for sys environment, I need to use gradle to perform those steps:</p>
  
  <p>1) execute buildSys in the APP project to create a war file for sys environment
  2) execute buildSysEAR that will package the created war file into an ear file.</p>
  
  <p>I am not sure if I need to have 3 tasks in my build.gradle for APP_EAR to package the ear file for each environment or whether I can do it with one ear task and make it call the appropriate war task for that environment.</p>
  
  <p>I just want to be able to execute one task that builds the war and the ear for this environment, I am not sure how to tie the war file to the ear file and/or trigger the correct build task for the war file from the APP_EAR build file.</p>
  
  <p>Thank you in advance</p>