title: How to execute JavaExec multiple times in a single task using Gradle?
body: <p>I have a task that runs a simple JavaExec. </p>
  
  <p>What I cant seem to get working is the ability to run the JavaExec multiple times while iterating a Filetree object (containing the files) each of while I want to pass into the main JavaExec class one by one. Unfortunately the compiler or code generation tool as it is doesnot accept a directory as an arg so I need to pass the file as an arg per loop. Here's what I have:</p>
  
  <pre><code>task generateClasses(type: JavaExec) {
     description = 'Generates Json Classes...'
     classpath configurations.all
     main = "org.apache.gora.compiler.Compiler"
     FileTree tree = fileTree(dir: 'src/main')
     tree.include '**/*.json'
         tree.each {File file -&gt;
         println file
         args = [ "src/main/json/$file.name", "$buildDir/generated-src/src/main/java" ]
     }    
  </code></pre>
  
  <p>}</p>
  
  <p>compileJava.source generateClasses.outputs.files, sourceSets.main.java</p>
  
  <p>From the above it works and I get all files listed but the JavaExec is called just the once on the very last file read.</p>
  
  <p>How do I address the above? Please help.</p>