title: Replace File in Gradle Build
body: <p>I am trying to replace a file in my resource folder (src/main/resources) with a new file generated by the Gradle build script.  I'm having trouble doing this; the exclusion seems to be remembered, and preventing the addition of my new file.</p>
  
  <p>Here's a short example that illustrates the behavior.</p>
  
  <p>Project Structure:</p>
  
  <pre><code>TestProject
  -- src/main/java
  ---- entry
  ------ EntryPoint.java
  ---- run
  ------ HelloWorldTest.java
  -- src/main/resources
  ---- test.properties // FILE TO REPLACE
  </code></pre>
  
  <p>test.properties contents in src/main/resources:</p>
  
  <p><code>Wrong File with extra text to make it obvious which one is being put into the jar based on size</code></p>
  
  <p>build.gradle:</p>
  
  <pre><code>apply plugin: 'java'
  
  task makeProp {
      def propDir = new File(buildDir, "props")
      ext.propFile = new File(propDir, "test.properties")
      outputs.file propFile
  
      doLast {
          propDir.mkdirs()
          propFile.createNewFile()
          propFile.withWriter('utf-8') { writer -&gt;
              writer.writeLine 'Right File'
          }
      }
  }
  
  jar {
      dependsOn('makeProp')
  
      if (project.hasProperty('testExclude')) {
          sourceSets {
              exclude('test.properties')
          }
      }
  
      from (makeProp.propFile) {
          into '/'
      }
  }
  </code></pre>
  
  <p>JAR contents of <code>./gradlew build</code> (both files included):</p>
  
  <pre><code>Archive:  TestProject.jar
    Length     Date   Time    Name
   --------    ----   ----    ----
          0  08-07-15 14:27   META-INF/
         25  08-07-15 14:27   META-INF/MANIFEST.MF
          0  08-07-15 13:50   run/
        499  08-07-15 13:50   run/HelloWorldTest.class
          0  08-07-15 13:50   entry/
       1413  08-07-15 13:50   entry/EntryPoint.class
         95  08-07-15 14:27   test.properties
         11  08-07-15 14:03   test.properties
   --------                   -------
       2043                   8 files
  </code></pre>
  
  <p>JAR contents of <code>./gradlew build -PtestExclude</code> (neither file included):</p>
  
  <pre><code>Archive:  TestProject.jar
    Length     Date   Time    Name
   --------    ----   ----    ----
          0  08-07-15 14:29   META-INF/
         25  08-07-15 14:29   META-INF/MANIFEST.MF
          0  08-07-15 13:50   run/
        499  08-07-15 13:50   run/HelloWorldTest.class
          0  08-07-15 13:50   entry/
       1413  08-07-15 13:50   entry/EntryPoint.class
   --------                   -------
       1937                   6 files
  </code></pre>