title: How to read a properties files and use the values in project Gradle script?
body: <p>I am working on a Gradle script where I need to read the <code>local.properties</code> file and use the values in the properties file in <code>build.gradle</code>. I am doing it in the below manner. I ran the below script and it is now throwing an error, but it is also not doing anything like creating, deleting, and copying the file. I tried to print the value of the variable and it is showing the correct value.</p>
  <p>Can someone let me know if this is the correct way to do this? I think the other way is to define everything in the <code>gradle.properties</code> and use it in the <code>build.gradle</code>. Can someone let me know how could I access the properties in <code>build.gradle</code> from <code>build.properties</code>?</p>
  <p><code>build.gradle</code> file:</p>
  <pre><code>apply plugin: 'java'
  
  // Set the group for publishing
  group = 'com.true.test'
  
  /**
   * Initializing GAVC settings
   */
  def buildProperties = new Properties()
  file(&quot;version.properties&quot;).withInputStream {
          stream -&gt; buildProperties.load(stream)
  }
  // If jenkins build, add the jenkins build version to the version. Else add snapshot version to the version.
  def env = System.getenv()
  if (env[&quot;BUILD_NUMBER&quot;]) buildProperties.test+= &quot;.${env[&quot;BUILD_NUMBER&quot;]}&quot;
  version = buildProperties.test
  println &quot;${version}&quot;
  
  // Name is set in the settings.gradle file
  group = &quot;com.true.test&quot;
  version = buildProperties.test
  println &quot;Building ${project.group}:${project.name}:${project.version}&quot;
  
  Properties properties = new Properties()
  properties.load(project.file('build.properties').newDataInputStream())
  def folderDir = properties.getProperty('build.dir')
  def configDir = properties.getProperty('config.dir')
  def baseDir  = properties.getProperty('base.dir')
  def logDir  = properties.getProperty('log.dir')
  def deployDir  = properties.getProperty('deploy.dir')
  def testsDir  = properties.getProperty('tests.dir')
  def packageDir  = properties.getProperty('package.dir')
  def wrapperDir  = properties.getProperty('wrapper.dir')
  
  
  sourceCompatibility = 1.7
  compileJava.options.encoding = 'UTF-8'
  
  repositories {
       maven { url &quot;http://arti.oven.c:9000/release&quot; }
    }
  
  task swipe(type: Delete) {
           println &quot;Delete $projectDir/${folderDir}&quot;
           delete &quot;$projectDir/$folderDir&quot;
           delete &quot;$projectDir/$logDir&quot;
           delete &quot;$projectDir/$deployDir&quot;
           delete &quot;$projectDir/$packageDir&quot;
           delete &quot;$projectDir/$testsDir&quot;
           mkdir(&quot;$projectDir/${folderDir}&quot;)
           mkdir(&quot;projectDir/${logDir}&quot;)
           mkdir(&quot;projectDir/${deployDir}&quot;)
           mkdir(&quot;projectDir/${packageDir}&quot;)
           mkdir(&quot;projectDir/${testsDir}&quot;)
  }
  task prepConfigs(type: Copy, overwrite:true, dependsOn: swipe) {
      println &quot;The name of ${projectDir}/${folderDir} and ${projectDir}/${configDir}&quot;
      from('${projectDir}/${folderDir}')
      into('${projectDir}/$configDir}')
      include('*.xml')
  }
  </code></pre>
  <p><code>build.properties</code> file:</p>
  <pre><code># -----------------------------------------------------------------
  # General Settings
  # -----------------------------------------------------------------
  application.name  = Admin
  project.name = Hello Cool
  
  # -----------------------------------------------------------------
  # ant build directories
  # -----------------------------------------------------------------
  sandbox.dir = ${projectDir}/../..
  reno.root.dir=${sandbox.dir}/Reno
  ant.dir = ${projectDir}/ant
  build.dir = ${ant.dir}/build
  log.dir  = ${ant.dir}/logs
  config.dir = ${ant.dir}/configs
  deploy.dir  = ${ant.dir}/deploy
  static.dir =  ${ant.dir}/static
  package.dir = ${ant.dir}/package
  tests.dir = ${ant.dir}/tests
  tests.logs.dir = ${tests.dir}/logs
  external.dir = ${sandbox.dir}/FlexCommon/External
  external.lib.dir = ${external.dir}/libs
  </code></pre>