title: Programmatically create a file in Gradle build script
body: <p>I'm sure it is trivial, but I cannot find a way to do it...</p>
  
  <p>In my <code>build.gradle</code> I want <code>processResources</code> task to create (not e.g. copy or fill some tempate) a resource file to be loaded by Java program.</p>
  
  <p>I achieved the following:</p>
  
  <pre><code>processResources {
      ...
  
      // This is a collection of files I want to copy into resources.
      def extra = configurations.extra.filter { file -&gt; file.isFile () }
  
      // This actually copies them to 'classes/extra'. It works.
      into ('extra') {
          from extra
      }
  
      doLast {
          // I want to write this string (list of filenames, one per
          // line) to 'classes/extra/list.txt'.
          println extra.files.collect { file -&gt; file.name }.join ("\n")
      }
  }
  </code></pre>
  
  <p>You can see above a <code>println</code> that prints exactly what I need. But how do I write this string to a file instead of the console?</p>