title: How to execute a shell command for each file in a Gradle file collection?
body: <p>I've recently been directed to implement all build/release engineering jobs in Gradle.</p>
  
  <p>So I'm new to Gradle and some things which are drop-dead obvious at a shell prompt are just hard to fathom in this brave new world.</p>
  
  <p>My build creates a set of jar files.</p>
  
  <p>I need to execute a shell task for each one of them</p>
  
  <p>Something similar to:</p>
  
  <pre><code>task findBugs (type:Exec, dependsOn:  fb23) {commandLine 'java', '-jar',
  './findBugs/findbugs.jar',  '-textui', '-progress', '-xml', '-output',
  'TrustManagerService.xml', 'TrustManagerService.jar'}
  </code></pre>
  
  <p>(I can't usethe FindBugs plug-in because we're in JDK8 - so I'm running FindBugs externally from a preview version...)</p>
  
  <p>I can get a file collection and iterate over the file names with something like:</p>
  
  <pre><code>FileTree iotTree = fileTree(dir: '.')
  iotTree.include '*.jar'
  iotTree.each {
  File file -&gt; println file.name
  println 'A file'
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>def iotJars = files(file('./jars').listFiles())
  println ''
  println iotJars
  iotJars.each { File file -&gt; println 'The next file is: ' + file.name }
  </code></pre>
  
  <p>But for the life of me I can't see how to execute a shell command for each filename returned...</p>
  
  <p>Thoughts on the most straightforward way to do this??</p>
  
  <p>By the way - what's the best way to include the line breaks in the code listing - I had to return and add CRs to each line to get them to break...:(</p>