How do I provide credentials for Gradle Wrapper without embedding them in my project's gradle-wrapper.properties file?
Asked Answered
G

2

11

In order to bootstrap Gradle-Wrapper, I need to pull the Gradle distribution from an Artifactory which requires HTTP Basic-Auth. There's no way for my build environment to access the outside world - this is blocked by the corporate proxy. My problem is how to provide the credentials so that Gradle can bootstrap.

The Gradle documentation suggests putting the username & password into gradle-werapper.properties.

If I put gradle-wrapper.properties into my project then anybody who has access to my source code would would have access to my credentials. Alternatively, if I put the gradle-wrapper.properties 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 the right way - but is there a way to make Gradle consume the credentials from an environment variable?

Goop answered 25/7, 2017 at 17:27 Comment(0)
B
13

From the documents you gave. In {user.home} directory create .gradle folder if it does not exist. enter gradle.properties:

systemProp.gradle.wrapperUser=username
systemProp.gradle.wrapperPassword=password

now all you need is distributionUrl to point to your URL, and gradle will handle credentials.

Butyraceous answered 12/12, 2017 at 8:15 Comment(3)
This does not seem to work. Keeps getting an error. Add the credentials to the url works great. https://username:password@url/repo/distributions/gradle-2.13-all.zip But is isn't what you want.Twodimensional
I am also getting nowhere when attempting to use artifactory as the repo. It might be an issue with artifactory? I'm not sure how to workaround this yet, or if there is one. Perhaps another auth method?Exhalation
This worked for me. I used the login username for Artifactory, and the Encrypted password for the password. Syncing again started downloading instead of giving me 401.Fanestil
O
7

There are three ways to provide credentials:

  1. In ~/.gradle folder create a file gradle.properties with
systemProp.gradle.wrapperUser=username
systemProp.gradle.wrapperPassword=password
  1. pass throw system properties ( note: username, password can be environment variables)
./gradlew -Dgradle.wrapperUser=$username -Dgradle.wrapperPassword=$password
  1. add system properties to GRADLE_OPTS
export GRADLE_OPTS=-Dgradle.wrapperUser=$username -Dgradle.wrapperPassword=$password
Oleviaolfaction answered 1/10, 2021 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.