title: Repository credentials work if they're hardcoded, but not if they're from gradle.properties
body: <h2>Problem</h2>
  
  <p>I am using Gradle and have my repository configurations, which require credentials. When I hardcode the username and password, everything works. When I try to store those same credentials in <code>gradle.properties</code> it doesn't.</p>
  
  <h2>Background</h2>
  
  <p>The repository declarations in my <code>build.gradle</code> file essentially looks like this:</p>
  
  <pre><code>repositories {
      maven {
          url 'https://artifactory.example.com/libs/'
          credentials {
              username "myUsername"
              password "myPassword"
          }
      }
  }
  </code></pre>
  
  <p>Everything works great and I can connect to my repository.</p>
  
  <h2>What isn't working</h2>
  
  <p>As you can see above, the username and password is hardcoded. I want to make it configurable, so I follow <a href="https://stackoverflow.com/q/25262562/531762">the advice in this question</a> add the following properties to <code>gradle.properties</code>.</p>
  
  <pre><code>storedUsername = "myUsername"
  storedPassword = "myPassword"
  </code></pre>
  
  <p>I then modify the <code>build.gradle</code> file to refer to those properties:</p>
  
  <pre><code>repositories {
      maven {
          url 'https://artifactory.example.com/libs/'
          credentials {
              username project.storedUsername
              password project.storedPassword 
          }
      }
  }
  </code></pre>
  
  <p>However, I am suddenly unable to connect to my repository. When I check my server (Artifactory) logs, I am told that access was denied to a user without a name.</p>
  
  <p>Both files are in the root directory as siblings. I've added <code>println "Username: ${project.repoUsername}"</code> to the <code>repositories{}</code> block, as well as both the <code>configurations {}</code> and <code>dependencies{}</code> blocks. They all correctly return the values they should.</p>
  
  <p>I suspect this may be a scoping issue, but I can't figure out where it is. What can I do to have both repositories in an external file and credentials in <code>gradle.properties</code>?</p>