How do I provide credentials for Gradle Wrapper without embedding them in my project's file?

In order to bootstrap Gradle-Wrapper, I need to pull the Gradle distribution from an Artifactory which requires HTTP Basic-Auth.

The Gradle documentation suggests putting the username & password into

If I put into my project then anybody who has access to my source code would would have access to my credentials. Alternatively, if I put the file into my build image then all of my builds will be tied to the same credentials. Neither of these are acceptable.

What I’d much rather do is have Gradle Wrapper pick up it’s credentials from environment variables. My run-time environment makes it very easy to provide the credentials in this way - but is there a way to make Gradle consume the credentials from an environment variable?


Same here! Did you find a way to use API Key ? Cheers.


It is my first post here so I hope it will be helpful.

A while ago have a similar task - build artifact and the put it in the Artifactory. And this was through CI Jenkins job.
Below is the build.gradle part related to the Artifactory credentials:

publishing {
   repositories {
        maven {
            name 'nexus'
            url "http://yourArtifactory:8081/repository/maven-snapshots/"
            credentials {
            	username System.getenv('ARTIFACTORY_USERNAME') 
      			password System.getenv('ARTIFACTORY_PASSWORD') 

In the CLI, gradlew consumes these variables as a system properties

gradlew clean build publish -DARTIFACTORY_USERNAME=xxx -DARTIFACTORY_PASSWORD=yyy

In my case, the credentials were exposed by Jenkins “Credentials Binding Plugin” so were hidden also in the console log from the job execution.

I see you asking about API Key… try to put your key instead of the password.
Some useful links:

Good luck!