title: How to do gradle resource filtering
body: <p>I'm developing a java web application using gradle. I want to test this application in different environment such as local, test site or live. I have an idea to replace the variable on properties file based on environment. Assume this web application is running on test site. Here is my code.</p>
  
  <p>build.gradle</p>
  
  <pre><code>import org.apache.tools.ant.filters.*
  import groovy.swing.*
  
  if(!hasProperty("profile")) {
      ext.profile = "test"
  }
  
  if(!hasProperty("deployTarget")) {
      ext.deployTarget = "local"
  }
  
  if(deployTarget == "local") 
  {
      apply from: "gradle-properties/local.properties"
  }
  else if(deployTarget == "test") 
  {
      apply from: "gradle-properties/test.properties"
  }
  else if(deployTarget == "live") 
  {
      apply from: "gradle-properties/live.properties"
  }
  
  processResources {
      from('src/main/resources') {
          include '*.properties'
          filter(ReplaceTokens, tokens: ['serverEnvironment': serverEnvironment])
      }
  }
  </code></pre>
  
  <p>gradle-properties/test.properties</p>
  
  <pre><code>ext.serverEnvironment="test"
  </code></pre>
  
  <p>src/main/resources/web.application.config.properties</p>
  
  <pre><code>server.environment=@serverEnvironment@
  </code></pre>
  
  <p>TestRestController.java</p>
  
  <pre><code>@RestController
  public class TestRestController {
  
      @Resource //tested @Inject also
      private Environment environment;
  
      @RequestMapping(value = "/test")
      public String testController() {
          return environment.getProperty("server.environment");
      }
  }
  </code></pre>
  
  <p>I'm getting "local" result from these code. Am I missed something important? Please advice, thanks a lot.</p>