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 gradle.properties
it doesn't.
The repository declarations in my build.gradle
file essentially looks like this:
repositories {
maven {
url 'https://artifactory.example.com/libs/'
credentials {
username "myUsername"
password "myPassword"
}
}
}
Everything works great and I can connect to my repository.
As you can see above, the username and password is hardcoded. I want to make it configurable, so I follow the advice in this question add the following properties to gradle.properties
.
storedUsername = "myUsername"
storedPassword = "myPassword"
I then modify the build.gradle
file to refer to those properties:
repositories {
maven {
url 'https://artifactory.example.com/libs/'
credentials {
username project.storedUsername
password project.storedPassword
}
}
}
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.
Both files are in the root directory as siblings. I've added println "Username: ${project.repoUsername}"
to the repositories{}
block, as well as both the configurations {}
and dependencies{}
blocks. They all correctly return the values they should.
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 gradle.properties
?
The configuration is correct, but the issue is with gradle.properties
. It is currently configured this way:
storedUsername = "myUsername"
storedPassword = "myPassword"
The issue is with the quotes. You don't have to surround the values on the right side of the equal signs as a string, so the quotes are treated as literals. In other words, the username you are sending to the server isn't myUsername
but instead is "myUsername"
, which presumably does not exist on the server.
Deleting the quotes will solve this issue:
storedUsername = myUsername
storedPassword = myPassword
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With