title: Injecting & Configuring Gradle Builds
body: <p>I'm reading up on Gradle and am very interested in it, specifically because (it <em>appears</em>) that it allows the introduction of inheritance into the build process. For instance, if I have a Java web app that might be packaged and deployed to Google App Engine instances as well as Amazon EC2 instances, I need a sophisticated build that can take the same Java, XML, PROPERTIES, CSS and image files and package/deploy them into 2 <em>drastically</em>-differently packaged <code>WAR</code> files.</p>
  
  <p>GAE apps are very specific as to how they are packaged; EC2 (pretty much) just require that you conform to servlet specs. GAE apps get "deployed" by running an <code>update</code> command from the <code>appcfg.sh</code> script that comes with your SDK; EC2 has their own way to deploy apps. The point is, they are very different packaging/deployment processes for both PaaS providers:</p>
  
  <pre><code>public abstract class PackageTask {
      // ...
  }
  
  // Package my Eclipse project for deployment to GAE.
  public class AppEnginePackageTask extends PackageTask {
      // ...
  }
  
  // Package my Eclipse project for deployment to EC2 instances.
  public class AmazonPackageTask extends PackageTask {
      // ...
  }
  
  public abstract class DeployTask {
      // ...
  }
  
  // Deployment to GAE.
  public class AppEngineDeployTask extends DeployTask {
      // ...
  }
  
  // Deployment to EC2.
  public class AmazonDeployTask extends DeployTask {
      // ...
  }
  </code></pre>
  
  <p>Then, I might have a <code>myapp.gradle</code> buildfile that templates the build order of tasks:</p>
  
  <pre><code>clean()
  compile()
  package()
  deploy()
  </code></pre>
  
  <p>...and somehow, I can configure/inject <code>AppEnginePackageTask</code>/<code>AppEngineDeployTask</code> in place of <code>package()</code>/<code>deploy()</code> for a GAE-based build, or I can configure/inject <code>AmazonPackageTask</code>/<code>AmazoneDeployTask</code> into those templated tasks. Again, I'm not sure how to do this (or even if Gradle <em>can</em> do this), but it's what I'm after.</p>
  
  <p>My <em>understanding</em> was that Gradle can do this.  Ant can also be forced to have highly-modular, elegant builds that work this way, but being XML-based, it takes some finessing, whereas an OOP-based language like Groovy makes this cleaner and simpler.</p>
  
  <p>However, all the examples I see of Gradle tasks take the following form:</p>
  
  <pre><code>task package(dependsOn: 'compile') {
      // ...
  }
  
  task deploy(dependsOn: 'package') {
      // ...
  }
  </code></pre>
  
  <p>So I ask: these look/feel like non-OOP task definitions. Is my understanding of Gradle (and its OOP nature) fundamentally incorrect? What am I missing here? How can I accomplish these notions of "configurable/injectable build templates" and inheritance-based tasks? Thanks in advance!</p>
  
  <p><strong>Edit</strong> I re-tagged this question with "<code>groovy</code>" because Gradle buildscripts are written in a Groovy DSL, and someone who happens to be a Groovy-guru (say that 5 times fast) might also be able to chime in even if they know little about Gradle.</p>