Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gradle

gradlew

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?

like image 743
Salim Fadhley Avatar asked Jul 25 '17 17:07

Salim Fadhley


People also ask

How do I make Gradle wrapper properties?

Just add wrapper task to build. gradle file and run this task to get the wrapper structure. task. Add the resulting files to SCM (e.g. git) and from now all developers will have the same version of Gradle when using Gradle Wrapper.

Where is the Gradle wrapper properties file?

The Wrapper shell script and batch file reside in the root directory of a single or multi-project Gradle build. You will need to reference the correct path to those files in case you want to execute the build from a subproject directory e.g. ../../gradlew tasks .

Should Gradle wrapper be committed?

From Gradle's documentation: The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper. jar bootstrap JAR file and properties file which should also be committed to your VCS.

How do you set up gradle wrappers?

To initially setup the wrapper, you will need to have Gradle installed on your machine first. Download it from the Gradle website, not forgetting to add the bin directory to your PATH environment variable. In an empty directory run gradle init to start the Gradle project setup wizard.


1 Answers

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.

like image 169
YoShade Avatar answered Mar 30 '23 00:03

YoShade