title: Gradle aggregation task
body: <p>In my gradle scripts, I've built a task that runs a java process. This process depends on a target property. The task is defined by:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>task('bulk', type: JavaExec, dependsOn: 'classes', description : 'Bulk data import on a target (defined by -Ptarget=[event|member|...]]') {
  
  //available imports
  ext{
      event = relativePath('src/main/scripts/events.csv')
      member = relativePath('src/main/scripts/member.csv')
      membership = relativePath('src/main/scripts/membership.csv')
  }
  
  //check the target is set 
  doFirst {
      if(!project.hasProperty('target')){
  
          println "\nUsage:"
          println "\tgradle bulk -Ptarget=[event|member|...]"
          println "where target is : "
          bulk.ext.each{ println it }
  
          throw new GradleException('Target argument required')
      } else {
          println "\nBulk import of  $target\n"
      }
  }
  
  main = 'org.yajug.users.bulkimport.BulkImport'
  classpath = sourceSets.main.runtimeClasspath
  if(project.hasProperty('target')){
      bulk{
              args target
              args bulk.ext[target]
          debug false
          }
      }
  }
  </code></pre>
  
  <p>And to run it:</p>
  
  <pre class="lang-bash prettyprint-override"><code>gradle bulk -Ptarget=event
  </code></pre>
  
  <p>It's working fine, but know I have to run this process for different targets:</p>
  
  <pre class="lang-bash prettyprint-override"><code>gradle bulk -Ptarget=event
  gradle bulk -Ptarget=member
  gradle bulk -Ptarget=membership
  ...
  </code></pre>
  
  <p><strong>How can I group all these calls into an other single task with the gradle's dependency model ?</strong> (I know the list of targets) </p>
  
  <p><strong>SOLUTION</strong></p>
  
  <pre class="lang-groovy prettyprint-override"><code>task bulk;
  ['event','member','membership'].each {target -&gt;
      task("bulk${target}", type: JavaExec, dependsOn: 'classes', description : "Bulk data import of ${target}s") {
  
          //available imports
          ext{
              event = relativePath('src/main/scripts/events.csv')
              member = relativePath('src/main/scripts/member.csv')
              membership = relativePath('src/main/scripts/membership.csv')
          }
  
          //check the target is set 
          doFirst {
              println "\nBulk import of  $target\n"
          }
  
          main = 'org.yajug.users.bulkimport.BulkImport'
          classpath = sourceSets.main.runtimeClasspath
          args target
          args ext[target]
          debug false
  
      }
      bulk.dependsOn("bulk${target}")
  }
  </code></pre>